Run Ansible adhoc commands in sequence

0 votes

I'm trying to run ansible adhoc commands on an ec2 instance on aws sequentially but I think its getting executed parallelly.

Something like this:

ansible aws -a "hostname"
ec2 | SUCCESS | rc=0 >>
ip-172-31-36-255

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

ansible aws -a "hostname"
ec3 | SUCCESS | rc=0 >>
ip-172-31-45-174

ec2 | SUCCESS | rc=0 >>
ip-172-31-36-255
Jan 14, 2019 in Ansible by Thomas
484 views

1 answer to this question.

0 votes

Hey @Thomas, by default ansible runs these commands parellely. If you want it to be executed sequencially then you need to explicitly mention it using --fork.

On adhoc command:

ansible aws -a "hostname" --forks=1

Inside the playbook:

- hosts: aws
  become: yes
  gather_facts: yes
  serial: 1
  tasks:
    - your tasks
answered Jan 14, 2019 by Barbara

Related Questions In Ansible

0 votes
1 answer

Is it possible to run commands on ansible host?

If you just trying to run a ...READ MORE

answered Jan 9, 2019 in Ansible by Vijay
443 views
0 votes
1 answer
0 votes
1 answer

Can we run parallel jobs in Ansible

Running parallel tasks in Ansible is not ...READ MORE

answered Aug 5, 2019 in Ansible by Kalgi
• 51,890 points
1,556 views
0 votes
1 answer

How to run Ansible-Playbook in the localhost?

Hi@akhtar, To run any playbook in the local ...READ MORE

answered 2 days ago in Ansible by MD
• 43,260 points
19 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,420 points
606 views
0 votes
1 answer
0 votes
1 answer

Is it possible to run an Ansible Playbook in python script?

Hey @Cerci, Of course its possible. You ...READ MORE

answered Jan 17, 2019 in Ansible by Nicolas
7,309 views
0 votes
1 answer

How to ignore failed commands in Ansible?

Usually, if even one command fails to ...READ MORE

answered Feb 7, 2019 in Ansible by Patt
8,320 views