Michael's recommendation of putting multiple plays in a playbook worked 
great for me. 

I ran a test and saw that all variables carry over between plays, so that 
if you do a lot of work to set up state, you don't lose that when you 
switch to a new play in the middle of a playbook.

Here is an example showing the general layout:

---
- hosts: dog,cat,opossum
  sudo: true
  vars:
    branch: "{{ NESTED.VARIABLE.BRANCH }}"
    version: "{{ NESTED.VARIABLE.version }}"

  pre_tasks:
    - name: Display all variables/facts known for a host
      debug: var=hostvars[inventory_hostname]

  roles:
    - { role: webserver, tags: [ animals, servers ] }

  tasks:
    - name: Complicated task
      shell: /bin/omg

    - name: Gather lots of data
      set_fact:
        dog_public_ips: "{% for host in groups.get("dog", []) %}{{ 
hostvars[host]["ec2_public_ip_address"] }} {% endfor %}"
        cat_public_ips: "{% for host in groups.get("cat", []) %}{{ 
hostvars[host]["ec2_public_ip_address"] }} {% endfor %}"
        opossum_public_ips: "{% for host in groups.get("opossum", []) %}{{ 
hostvars[host]["ec2_public_ip_address"] }} {% endfor %}"

    - name: Display all variables/facts known for a host
      debug: var=hostvars[inventory_hostname]

## Just run this section 2 hosts at a time to limit the number of servers 
disrupted at any given time

- hosts: dog,cat,opossum
  sudo: true
  serial: 2

  tasks:
    - name: Display all variables/facts known for a host
      debug: var=hostvars[inventory_hostname]


In this, facts like "dog_public_ips" are still available in the second 
"serial" play.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ef191483-eab0-4011-b6cf-865990980a92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to