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
   - launchEc2
 - hosts: ansible
   gather_facts: Fasle
   become: yes   
   - python


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

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

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

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

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

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

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

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

PLAY RECAP *********************************************************************                  : ok=5    changed=2    unreachable=0    failed=0              : ok=0    changed=0    unreachable=0    failed=0
Jun 25, 2018 in Ansible by Damon Salvatore
• 5,980 points

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, 2019 in Ansible by Nigya

edited Jan 18, 2019 by Vardhan 7,188 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, 2019 in Ansible by Nicolas
0 votes
1 answer
0 votes
1 answer
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 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
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