Last active
May 13, 2018 09:48
-
-
Save romainx/681f9ea6a96ebe79ea970289cae1a59f to your computer and use it in GitHub Desktop.
Sample Ansible Playbook listing EC2 t2.micro instances
This file contains 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
--- | |
# Source: https://gist.github.com/romainx/681f9ea6a96ebe79ea970289cae1a59f | |
- name: List EC2 instances | |
hosts: localhost | |
# To run the playbook locally | |
# http://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#local-playbooks | |
connection: local | |
# There is no need to gather facts here | |
gather_facts: false | |
vars: | |
# To tell ansible to use the Python env just created, if not set the default interpreter will be used | |
# Ref.: https://stackoverflow.com/questions/41774695/ansible-ec2-boto-required-for-this-module | |
- ansible_python_interpreter: "/Users/xxxx/anaconda/envs/aws/bin/python" | |
- instance_type: "t2.micro" | |
tasks: | |
- name: "List EC2 {{ instance_type }} instances" | |
ec2_instance_facts: | |
aws_access_key: "AXXX" | |
aws_secret_key: "XXX" | |
region: "eu-west-1" | |
filters: | |
instance-type: "{{ instance_type }}" | |
register: ec2 | |
- name: Print EC2 instances | |
debug: | |
var: ec2.instances |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment