Ansible role execution order is not serial

405 views
Skip to first unread message

Tung Nguyen

unread,
Apr 11, 2016, 9:51:05 AM4/11/16
to Ansible Project
I have a set of custom roles like this on AWS EC2

---
- hosts: test
  roles
:
   
- common
   
- deploy
   
- deploy_asg

    
Basically install some common stuff then deploy the new code on running servers (deploy role) then take snapshot of one of them and update the autoscale group (deploy_asg role).

The thing is the `ec2_ami` (in deploy_asg role) always create the new AMI before the `deploy` role finish, so the AMI state is not the same as the running servers.

I tried to use `pause` and separate the main playbook like this
---
- hosts: test
  roles
:
   
- common
   
- deploy


  post_tasks
:
   
- pause: seconds=60


  roles
:
   
- deploy_asg


But the `pause` task will run after the `deploy_asg` role.
What do you guys think?

Brian Coca

unread,
Apr 11, 2016, 11:41:20 PM4/11/16
to ansible...@googlegroups.com
you cannot have multiple roles: declarations per play, if you want to make this work in that order you need a 2nd play:

---
- hosts: test
  roles:
    - common
    - deploy
  tasks:
    - pause: seconds=60

- hosts: test
  roles:
    - deploy_asg


Also pause will start when the 1st host gets to it and it is global for all hosts, if you want EACH host to wait for a period use wait_for instead.


----------
Brian Coca

Josh Smift

unread,
Apr 12, 2016, 10:18:06 AM4/12/16
to ansible...@googlegroups.com
BC> you cannot have multiple roles: declarations per play, if you want to
BC> make this work in that order you need a 2nd play:

If you really needed to do it in one play for some reason, you could have
a 'pause' (or whatever) role, with one pause (or wait_for) task.

-Josh (j...@care.com)



This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
Reply all
Reply to author
Forward
0 new messages