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 in Ansible by Thomas
104 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 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 in Ansible by Vijay
85 views
0 votes
1 answer

Can we run parallel jobs in Ansible

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

answered Aug 5 in Ansible by Kalgi
• 40,420 points
32 views
0 votes
1 answer

How do I execute a shell script and then use the result in ansible

This can work out for you: - name: ...READ MORE

answered Apr 11, 2018 in Ansible by shubham
• 6,890 points
746 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,380 points
145 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 in Ansible by Nicolas
1,845 views
0 votes
1 answer

How to ignore failed commands in Ansible?

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

answered Feb 7 in Ansible by Patt
1,740 views