Iterate on more than one task: shell and pause

63 views
Skip to first unread message

Tzach Livyatan

unread,
Feb 4, 2015, 2:25:42 AM2/4/15
to ansible...@googlegroups.com
Hello again
I have a command to execute X times, pausing for a few second after each iteration.
One (working) way to do it is:
    - shell: sleep 60; the-command
      with_sequence
: count={{X}}

 But its look ugly to me:
- does not use built-in pause command
- make each of the host iterate independently, which may cause sync issue
 
I would like to do something like (not legal)
    - shell: the-command
      action
: pause: seconds=60
      with_sequence
: count={{X}}
Using include for the two tasks didnt work either as include and with_items is deprecated.

What is the right solution in this case?
Thanks
Tzach


Giovanni Tirloni

unread,
Feb 4, 2015, 5:54:30 AM2/4/15
to ansible...@googlegroups.com
I think your initial solution is the cleanest way to do this right now.

I was thinking if the shell module could be enhanced to accept a pause
parameter, but I don't know how Ansible "unroll" the list of activities
that should be carried out when there is looping involved. The module
might not even know it's going to run multiple times (so then it
couldn't pause anything, because it'd think it's running just once).

If that's the case, then perhaps the looping construct(s) would have to
accept a pause parameter.

Perhaps something like the concept of "blocks" [1] being worked on in v2
might help your situation. Create a block with a shell and a pause task
and iterate over them.

[1] -
https://groups.google.com/d/msg/ansible-project/4IXdJqzhuM8/aGIJglZ8G_4J

Giovanni

Tzach Livyatan

unread,
Feb 4, 2015, 9:40:51 AM2/4/15
to ansible...@googlegroups.com
Thanks Giovanni

Yes, block is what I was looking for.
Glad to see it will be available in v2.

I guess Greenspun's tenth rule apply to configuration mgmt SDL as well :)

 

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/c3KOpaoMnhQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1423047263.4066176.222930137.04FE27E8%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards 
@TzachL
Reply all
Reply to author
Forward
0 new messages