Skip to content

Instantly share code, notes, and snippets.

@bearice
Created December 4, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearice/d2f0220e6a446ea668a9a325d5e1e1c3 to your computer and use it in GitHub Desktop.
Save bearice/d2f0220e6a446ea668a9a325d5e1e1c3 to your computer and use it in GitHub Desktop.
Ansible playbook to control AWS Auto-scale group members dynmically.
---
- 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