Playbook to gather ec2_asg_facts AWS auto scaling group

0 votes
I need to gather ec2_asg_facts about a particular AWS auto scaling group. How do I write a playbook for the same?
Apr 2 in Ansible by Neha
218 views

1 answer to this question.

0 votes

Hey @Neya, try something like this:

---
- name: Create a new Demo EC2 instance
  hosts: localhost
  connection: local
  gather_facts: False

  tasks:

    - name: Find ASG in AWS
      ec2_asg_facts:
         aws_access_key: ------------------------
         aws_secret_key: ----------------------
         region: us-east-1
      register: auto_scaling_group
      register: ec2_asg_facts_results
    - name: Create list of instance_ids
      set_fact:
       ec2_asg_instance_ids: "{{ ec2_asg_facts_results.results[0].instances | map(attribute='instance_id') | list }}"
    - name: EC2 facts
      ec2_remote_facts:
       region: us-east-1
       aws_access_key: ---------------------------------
       aws_secret_key: ---------------------------------
       filters:
           instance-id: "{{ ec2_asg_instance_ids.instances[0].interfaces | map(attribute='id') }}"
answered Apr 2 by Pam

Related Questions In Ansible

0 votes
1 answer

Playbook to get my current IP - Ansible and AWS

Hey Komal, that's pretty simple. Try this: - ...READ MORE

answered Mar 24 in Ansible by Aarohi
80 views
0 votes
1 answer
0 votes
1 answer

Running to plays in one playbook

The inventory file is loaded before a ...READ MORE

answered Jun 25, 2018 in Ansible by ajs3033
• 7,280 points
45 views
0 votes
1 answer

devops , how to create user using ansible playbook

root doesn't need a password to switch ...READ MORE

answered Jul 16, 2018 in Ansible by Kalgi
• 2,620 points
141 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+1 vote
4 answers

Pass variable to ansible playbook through command line

ansible-playbook test.yml --extra-vars "arg1=${var1} arg2=${var2}" Use is like ...READ MORE

answered May 7 in Ansible by Bobin
4,861 views
0 votes
1 answer

Ansible playbook to wget a file

Hey @Celia, one recommendation, try not using ...READ MORE

answered Jan 16 in Ansible by Vaishu
2,110 views