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
1,792 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, 2020 in Ansible by MD
• 95,460 points
3,825 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
1,322 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 9, 2019 in Ansible by Anshul
975 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, 2020 in Ansible by MD
• 95,460 points
1,452 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

AWS ECS Service for Wordpress

If your container needs access to the ...READ MORE

answered Sep 20, 2018 in AWS by Priyaj
• 58,020 points
1,539 views
+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
14,393 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
17,664 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP