Running to plays in one playbook

0 votes

I want to run two plays in a single playbook. I want them to run in chronological order. The first play adds some new entries in the inventory file by making new group and the second play uses the new inventory file to run its tasks.

It run successfully if I execute them separately, but I want them in the same group.

Here's My play:

---
 - name: ec2
   hosts: localhost
   connection: local
   roles:
   - launchEc2
 - hosts: ansible
   gather_facts: Fasle
   become: yes   
   roles:
   - python

OUTPUT:

PLAY [ec2] *********************************************************************

TASK [setup] *******************************************************************
ok: [127.0.0.1]

TASK [launchEc2 : include_vars] ************************************************
ok: [127.0.0.1]

TASK [launchEc2 : Launch new ec2 instance] *************************************
changed: [127.0.0.1]

TASK [launchEc2 : Add ec2 ip to the hostgroup] *********************************
changed: [127.0.0.1] => (item={.....})

TASK [launchEc2 : wait for SSh to come up] *************************************
ok: [127.0.0.1] => (item={.....})

PLAY [ansible] *****************************************************************

TASK [python : install python] *************************************************
skipping: [34.203.228.19]

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=5    changed=2    unreachable=0    failed=0   
34.203.228.19              : ok=0    changed=0    unreachable=0    failed=0
Jun 25, 2018 in Ansible by Damon Salvatore
• 5,510 points
37 views

1 answer to this question.

0 votes

The inventory file is loaded before a playbook is executed. What's happening is, your second play is using the same inventory file to execute itself. 

As a workaround you can try to run refresh_inventory after you update it, but I'm not entirely sure that it'll work.

answered Jun 25, 2018 by ajs3033
• 7,280 points

Related Questions In Ansible

0 votes
1 answer

Ansible playbook for moving files from one node to another remote node

The best way to do this is: copy ...READ MORE

answered Jan 16 in Ansible by Nigya

edited Jan 18 by Vardhan 1,236 views
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
2,651 views
0 votes
1 answer
0 votes
1 answer
+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
211 views
0 votes
1 answer
0 votes
1 answer

When conditional not working in Ansible

Your identation is wrong and when is ...READ MORE

answered Apr 27, 2018 in Ansible by ajs3033
• 7,280 points
861 views
0 votes
1 answer

unable to build grails war on a vagrant machine using ansible

Try and run the command using shell ...READ MORE

answered Jul 2, 2018 in Ansible by ajs3033
• 7,280 points
73 views