Hi Vladimir,
Per suggestion, i have added the mentioned variable but still something is
missing and i got below error:
The conditional check 'data_done' failed. The error was: Unexpected
templating type error occurred on ({{ variable_data|
selectattr('percent_complete', 'ne', 100) | length == 0 }}): object of type
'generator' has no len()
Could you please assist? Thank you
This playbook is for NetApp storage module. moule '*na_ontap_volu**me*'
using for moving volume data from one aggregate(pool) to another.
Once 'Volume move' task is executed, I need to keep checking the status of
volume move until 100% completed ( percent_complete ) in the list.
---
- hosts: all
connection: local
gather_facts: false
collections:
- netapp.ontap
vars:
login: &login
username: "{{ admin_username }}"
password: "{{ admin_password }}"
https: true
validate_certs: false
use_rest: Always
tasks:
- name: block section task
block:
- name: Volume move
na_ontap_volume:
<<: *login
aggregate_name: "{{ aggregate_name }}"
vserver: svm1
name: vol1
hostname: "{{ inventory_hostname }}"
register: ontap_volume
no_log: false
- name: run ontap rest cli command to check volume move status
netapp.ontap.na_ontap_rest_cli:
<<: *login
hostname: "{{ inventory_hostname }}"
command: 'volume/move?fields=percent-complete,state'
params:
volume: '*'
vserver: '*'
verb: 'GET'
register: variable_data
- debug: var=variable_data # output mentioned below
- set_fact:
data_done: "{{ variable_data| selectattr('percent_complete',
'ne', 100)| len() == 0 }}"
- name: Retry a task until a certain condition is met
debug:
# register:
until: data_done
retries: 5
delay: 10
the output of "*variable_data*"
TASK [debug] ****************
ok: [cluster1] => {
"variable_data": {
"changed": true,
"failed": false,
"msg": {
"num_records": 3,
"records": [
{
"percent_complete": 30,
"state": "done",
"volume": "vol1",
"vserver": "svm1"
},
{
"percent_complete": 98,
"state": "healthy",
"volume": "vol2",
"vserver": "svm1"
},
{
"percent_complete": 50,
"state": "done",
"volume": "vol1",
"vserver": "svm2"
}
]
}
}
}
On Wed, Jun 21, 2023 at 6:36 AM Vladimir Botka <[email protected]> wrote:
> On Tue, 20 Jun 2023 22:18:22 +0530
> Aharonu <[email protected]> wrote:
>
> > I have *variable_data *which contains 3 records. I want to keep run
> > *debug *task
> > continuously every 1 minute until *percent_complete* == 100 and then
> > complete task execution.
>
> Given the list for testing
>
> variable_data:
> - {percent_complete: 100, volume: vol1, vserver: svm1}
> - {percent_complete: 100, volume: vol2, vserver: svm1}
> - {percent_complete: 100, volume: vol3, vserver: svm2}
>
> a task will complete when all *percent_complete* == 100
>
> data_done: "{{ variable_data|
> selectattr('percent_complete', 'ne', 100)|
> length == 0 }}"
>
> Without knowing the source of *variable_data* it's not possible to
> tell you how such a task should look like. Generally, you should test
> *data_done*, set delay, and how many times you want to retry
>
> until: data_done
> delay: 60
> retries: 999
>
> See "Retrying a task until a condition is met*
>
> https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#retrying-a-task-until-a-condition-is-met
>
> Moving forward you should briefly describe at least: the inventory,
> the source of the items(tasks, processes, ...) to be completed, and
> how you consolidate *variable_data*.
>
> Make it "Minimal reproducible example". See
> https://en.wikipedia.org/wiki/Minimal_reproducible_example
>
>
> --
> Vladimir Botka
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CANGEjuWdXd9xYt8ruX8EtLk%2BREYaTTttxR74eRxnyMHTcQUkKg%40mail.gmail.com.