[ansible-project] Re: Ansible task execution until it completes

2023-06-22 Thread Vladimir Botka
On Thu, 22 Jun 2023 10:55:32 +
Aharonu  wrote:

> ...
> Can we get output of only MSG instead of listing all other output so that i
> can see the required output?

This is the list of the records *variable_data.msg.records*

I can't provide you with better answer without "Minimal reproducible
example". 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230622180408.3b57e762%40gmail.com.


pgpWAqYB4j7QP.pgp
Description: OpenPGP digital signature


[ansible-project] Re: Ansible task execution until it completes

2023-06-22 Thread Aharonu
HI Vladimir,

Thank you again.

I think that is what I am looking for but it is when running with verbosity
( -).

Could you please go through below mentioned -vvv output where i can see
required output under MSG ( highlighted in blue):

Can we get output of only MSG instead of listing all other output so that i
can seethe required output?


TASK [run ontap rest cli command for vol move resister variabele]

***
task path: /home/user1/facts/netapp_volume_move.yml:38
< removed some data >
"attempts": 1,
"changed": true,
"invocation": {
"module_args": {
"body": {},
"cert_filepath": null,
"command": "volume/move?fields=percent-complete,state",
"feature_flags": {},
"hostname": "Cluster1",
"http_port": null,
"https": true,
"key_filepath": null,
"ontapi": null,
"params": {
"volume": "*",
"vserver": "*"
},
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"use_rest": "Always",
"username": "user1",
"validate_certs": false,
"verb": "GET"
}
},
"retries": 36
}

*MSG:*

{'records': [{'vserver': 'svm1', 'volume': 'svm1_mp_v3', 'state': 'done',
'percent_complete': 100}, {'vserver': 'svm2', 'volume':
'user1_test_clone2', 'state': 'done', 'percent_complete': 100}, {'vserver':
'svm2', 'volume': 'user1_test_clone3', 'state': 'healthy',
'percent_complete': 98}], 'num_records': 3}
< removed some data >
FAILED - RETRYING: run ontap rest cli command for vol move resister
variabele (34 retries left).Result was: {
"attempts": 2,
"changed": true,
"invocation": {
"module_args": {
"body": {},
"cert_filepath": null,
"command": "volume/move?fields=percent-complete,state",
"feature_flags": {},
"hostname": "Cluster1",
"http_port": null,
"https": true,
"key_filepath": null,
"ontapi": null,
"params": {
"volume": "*",
"vserver": "*"
},
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"use_rest": "Always",
"username": "user1",
"validate_certs": false,
"verb": "GET"
}
},
"retries": 36
}

*MSG:*

{'records': [{'vserver': 'svm1', 'volume': 'svm1_mp_v3', 'state': 'done',
'percent_complete': 100}, {'vserver': 'svm2', 'volume':
'user1_test_clone2', 'state': 'done', 'percent_complete': 100}, {'vserver':
'svm2', 'volume': 'user1_test_clone3', 'state': 'healthy',
'percent_complete': 98}], 'num_records': 3}
< removed some data >
FAILED - RETRYING: run ontap rest cli command for vol move resister
variabele (33 retries left).Result was: {
"attempts": 3,
"changed": true,
"invocation": {
"module_args": {
"body": {},
"cert_filepath": null,
"command": "volume/move?fields=percent-complete,state",
"feature_flags": {},
"hostname": "Cluster1",
"http_port": null,
"https": true,
"key_filepath": null,
"ontapi": null,
"params": {
"volume": "*",
"vserver": "*"
},
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"use_rest": "Always",
"username": "user1",
"validate_certs": false,
"verb": "GET"
}
},
"retries": 36
}

*MSG:*

{'records': [{'vserver': 'svm1', 'volume': 'svm1_mp_v3', 'state': 'done',
'percent_complete': 100}, {'vserver': 'svm2', 'volume':
'user1_test_clone2', 'state': 'done', 'percent_complete': 100}, {'vserver':
'svm2', 'volume': 'user1_test_clone3', 'state': 'healthy',
'percent_complete': 98}], 'num_records': 3}
< removed some data >
FAILED - RETRYING: run ontap rest cli command for vol move resister
variabele (32 retries left).Result was: {
"attempts": 4,
"changed": true,
"invocation": {
"module_args": {
"body": {},
"cert_filepath": null,
"command": "volume/move?fields=percent-complete,state",
"feature_flags": {},
"hostname": "Cluster1",
"http_port": null,
"https": true,
"key_filepath": null,
"ontapi": null,
"params": {
"volume": "*",
"vserver": "*"
},
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"use_rest": "Always",
"username": "user1",
"validate_certs": false,
"verb": "GET"
}
},
"retries": 36
}

*MSG:*

{'records': [{'vserver': 'svm1', 'volume': 'svm1_mp_v3', 'state': 'done',
'percent_complete': 

[ansible-project] Re: Ansible task execution until it completes

2023-06-21 Thread Vladimir Botka
On Wed, 21 Jun 2023 19:34:21 +
Aharonu  wrote:

>   - 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
> ...
>
> 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"
> }
> ]
> }
> }
> }

Try the tasks below. Register the *variable_data* in the first task
and use it in the starting *until* condition of the second task. You
want to repeat it every 1 minute. Set *delay* 60 seconds and *retry*
for example 60 times (1 hour)

  - 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

  - 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
until: variable_data.msg.records|
   selectattr('percent_complete', 'ne', 100)|
   list|length == 0
delay: 60
retry: 60

This way you are actually monitoring the volumes. But, Ansible can't
provide you with any intermediate data. The task is running on the
remote host and you'll see the results once the task completes and
returns the results to the controller.

Try to configure NetApp system monitors if you want to see any
progress . See
https://docs.netapp.com/us-en/cloudinsights/task_system_monitors.html#monitor-descriptions


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230622003939.574e99a0%40gmail.com.


pgpj4bs4mzFPZ.pgp
Description: OpenPGP digital signature


[ansible-project] Re: Ansible task execution until it completes

2023-06-21 Thread Aharonu
Hi Vladimir,

I have added* |list* and execute below task in ansible [core 2.11.12] but
no luck. Not getting where is stopping.

*Error:*

TASK [set_fact] *
fatal: [10.250.198.160]: FAILED! => {}

MSG:

The task includes an option with an undefined variable. The error was:
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute
'percent_complete'

The error appears to be in '/home/u630850/facts/netapp_volume_move.yml':
line 48, column 19, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  - debug: var=variable_data
  ^ here

There appears to be both 'k=v' shorthand syntax and YAML in this task. Only
one syntax may be used.

*Playbook as previously mentioned:*
 ---
- hosts: all
  connection: local
  gather_facts: false
  collections:
- netapp.ontap
  vars:
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)|list| length == 0}}"  - name: Retry a task until a certain
condition is metdebug:  # register:until: data_done
retries: 5delay: 10*





*the output of "variable_data"*
*TASK [debug] ok: [c*luster1] => {
"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 5:59 PM Aharonu  wrote:

> Hi Vladimir,
>
> Thank you.
>
> I will check in higher version and update the status how it works.
>
> On Wed, 21 Jun 2023, 21:59 Vladimir Botka,  wrote:
>
>> On Wed, 21 Jun 2023 11:08:16 +
>> Aharonu  wrote:
>>
>> > 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()
>>
>> Add the explicit conversion to *list*
>>
>>   data_done: "{{ variable_data|
>>  selectattr('percent_complete', 'ne', 100)|
>>  list|length == 0 }}"
>>
>> This has already been fixed. If you can update the latest version.
>>
>> --
>> 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANGEjuVydnsT_OEnSNe0i%3DeD006mipKzX38%3DGw%3D4wn6j__aMYQ%40mail.gmail.com.


[ansible-project] Re: Ansible task execution until it completes

2023-06-21 Thread Aharonu
Hi Vladimir,

Thank you.

I will check in higher version and update the status how it works.

On Wed, 21 Jun 2023, 21:59 Vladimir Botka,  wrote:

> On Wed, 21 Jun 2023 11:08:16 +
> Aharonu  wrote:
>
> > 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()
>
> Add the explicit conversion to *list*
>
>   data_done: "{{ variable_data|
>  selectattr('percent_complete', 'ne', 100)|
>  list|length == 0 }}"
>
> This has already been fixed. If you can update the latest version.
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANGEjuVt6V5efydaC6WtZA84wmgWUwANy%2BuZ2ZZoBgQyPK-O5w%40mail.gmail.com.


[ansible-project] Re: Ansible task execution until it completes

2023-06-21 Thread Vladimir Botka
On Wed, 21 Jun 2023 11:08:16 +
Aharonu  wrote:

> 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()

Add the explicit conversion to *list*

  data_done: "{{ variable_data|
 selectattr('percent_complete', 'ne', 100)|
 list|length == 0 }}"

This has already been fixed. If you can update the latest version.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230621182935.45d476aa%40gmail.com.


pgpJDifScjNp8.pgp
Description: OpenPGP digital signature


[ansible-project] Re: Ansible task execution until it completes

2023-06-21 Thread Aharonu
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: 
  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  wrote:

> On Tue, 20 Jun 2023 22:18:22 +0530
> Aharonu  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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANGEjuWdXd9xYt8ruX8EtLk%2BREYaTTttxR74eRxnyMHTcQUkKg%40mail.gmail.com.


[ansible-project] Re: Ansible task execution until it completes

2023-06-21 Thread Vladimir Botka
On Tue, 20 Jun 2023 22:18:22 +0530
Aharonu  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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230621083618.30b488d1%40gmail.com.


pgp6Ulp6wz2ka.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Re: Ansible task execution until it completes

2023-06-20 Thread Kosala Atapattu
Have you tried something like following?

- name: wait for a url to work
ansible.builtin.get_url:
url: "https://myservice/;
dest: "/tmp/"
register: result
retries: 10
delay: 6
until: result.rc == 0

SInce your record is a json you should be able to pull that off easily.

Cheers,
*Kosala*




On Wed, Jun 21, 2023 at 6:26 AM Aharonu  wrote:

> The play *(debug)* should execute every 1min and *percent_complete* will
> get changed every time till 100.
>
> When *percent_complete* is reached 100 for every record in the
> *variable_data*, the play should exit.
>
> Please help to achieve. Thank You.
>
>
>
> On Tue, 20 Jun 2023, 22:18 Aharonu,  wrote:
>
>> Dear All,
>>
>> Could you please help with the below query.
>>
>> 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.
>>
>> Please help to achieve my requirement. Thank you  in advance.
>>
>> TASK [debug] ***
>> ok: [cluster1] => {
>> "variable_data.msg": {
>> "num_records": 3,
>> "records": [
>> {
>> "percent_complete": 20,
>> "state": "in-progress",
>> "volume": "vol1",
>> "vserver": "svm1"
>> },
>> {
>> "percent_complete": 50,
>> "state": "in-progress",
>> "volume": "vol2",
>> "vserver": "svm1"
>> },
>> {
>> "percent_complete": 80,
>> "state": "in-progress",
>> "volume": "vol3",
>> "vserver": "svm2"
>> }
>> ]
>> }
>> }
>>
>>
>> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CANGEjuVE_Dgg-rb9%2B15Uak%3DOywdi2Ts1HXXdWh40EY%3Do7iy89g%40mail.gmail.com
> 
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAP7S5HaDJVEHTg0mPV9boNn%2BCB_RadaAqNaxb8gXaxKFJA%2BS0g%40mail.gmail.com.


[ansible-project] Re: Ansible task execution until it completes

2023-06-20 Thread Aharonu
The play *(debug)* should execute every 1min and *percent_complete* will
get changed every time till 100.

When *percent_complete* is reached 100 for every record in the
*variable_data*, the play should exit.

Please help to achieve. Thank You.



On Tue, 20 Jun 2023, 22:18 Aharonu,  wrote:

> Dear All,
>
> Could you please help with the below query.
>
> 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.
>
> Please help to achieve my requirement. Thank you  in advance.
>
> TASK [debug] ***
> ok: [cluster1] => {
> "variable_data.msg": {
> "num_records": 3,
> "records": [
> {
> "percent_complete": 20,
> "state": "in-progress",
> "volume": "vol1",
> "vserver": "svm1"
> },
> {
> "percent_complete": 50,
> "state": "in-progress",
> "volume": "vol2",
> "vserver": "svm1"
> },
> {
> "percent_complete": 80,
> "state": "in-progress",
> "volume": "vol3",
> "vserver": "svm2"
> }
> ]
> }
> }
>
>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANGEjuVE_Dgg-rb9%2B15Uak%3DOywdi2Ts1HXXdWh40EY%3Do7iy89g%40mail.gmail.com.