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, 2019 in Ansible by Neha
462 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, 2019 by Pam

Related Questions In Ansible

0 votes
1 answer

How to create a security group in AWS using Ansible-Playbook?

Hi@akhtar, You can use the ec2_group module in ...READ MORE

answered Aug 13 in Ansible by MD
• 54,360 points
122 views
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, 2019 in Ansible by Aarohi
232 views
0 votes
1 answer

Playbook to get all the container's ARN's in my AWS ECS cluster

Hey @haseeb, you could try something like ...READ MORE

answered Apr 8, 2019 in Ansible by Anshul
170 views
0 votes
1 answer

How to create a key pair on AWS using Ansible-Playbook?

Hi@akhtar, You can find the ec2_key module in ...READ MORE

answered Aug 12 in Ansible by MD
• 54,360 points
44 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, 2019 in Ansible by Bobin
9,880 views
0 votes
1 answer

Ansible playbook to wget a file

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

answered Jan 16, 2019 in Ansible by Vaishu
6,105 views