Created
December 4, 2017 07:00
-
-
Save bearice/d2f0220e6a446ea668a9a325d5e1e1c3 to your computer and use it in GitHub Desktop.
Revisions
-
bearice created this gist
Dec 4, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 }}"