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,980 points
1,279 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,300 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 9,581 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
15,740 views
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
4,062 views
+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,300 points
5,626 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,300 points
869 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP