Created
December 4, 2017 07:00
-
-
Save bearice/d2f0220e6a446ea668a9a325d5e1e1c3 to your computer and use it in GitHub Desktop.
Ansible playbook to control AWS Auto-scale group members dynmically.
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 characters
--- | |
- 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 }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment