Skip to content

Instantly share code, notes, and snippets.

@bearice
Created December 4, 2017 07:00
Show Gist options
  • Select an option

  • Save bearice/d2f0220e6a446ea668a9a325d5e1e1c3 to your computer and use it in GitHub Desktop.

Select an option

Save bearice/d2f0220e6a446ea668a9a325d5e1e1c3 to your computer and use it in GitHub Desktop.

Revisions

  1. bearice created this gist Dec 4, 2017.
    20 changes: 20 additions & 0 deletions apply_role_asg.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    ---
    - hosts: localhost
    connection: local
    gather_facts: no
    tasks:
    - name: query instances
    ec2_instance_facts:
    filters:
    "tag:aws:autoscaling:groupName": "{{asg_name}}"
    register: instance_facts

    - debug: msg={{ instance_facts.instances | selectattr('state.name', 'equalto', 'running') | map(attribute='instance_id') | list}}
    - name: group hosts
    add_host: hostname={{ item }} groups=asg-dyn-targets
    with_items: "{{ instance_facts.instances | selectattr('state.name', 'equalto', 'running') | map(attribute='private_ip_address') | list }}"

    - hosts: asg-dyn-targets
    become: yes
    roles:
    - role: "{{ role }}"