Search code examples
ansibleansible-2.xansible-ad-hoc

Ansible adhoc command in sequence


I want to run ansible adhoc command on a list of EC2 instances. I want ansible to run it in sequence but ansible runs them in random. For example:

13:42:21 @cnayak ansible :► ansible aws -a "hostname"
ec2 | SUCCESS | rc=0 >>
ip-172-31-36-255

ec3 | SUCCESS | rc=0 >>
ip-172-31-45-174

13:42:26 @cnayak ansible :► ansible aws -a "hostname"
ec3 | SUCCESS | rc=0 >>
ip-172-31-45-174

ec2 | SUCCESS | rc=0 >>
ip-172-31-36-255

Any way to make them run in order?


Solution

  • By default ansible runs tasks in parallel. If you want them to be executed serially then you can limit number of workers running at the same time by using "--forks" option.

    Adding "--forks 1" to your ansible invocation should run your command sequentially on all hosts (in order defined by inventory).