Skip to content

Instantly share code, notes, and snippets.

@jimpick
Created October 26, 2019 18:52
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 jimpick/c2fc494adde2c0e83eba68ed2ac8ce8e to your computer and use it in GitHub Desktop.
Save jimpick/c2fc494adde2c0e83eba68ed2ac8ce8e to your computer and use it in GitHub Desktop.
Ansible + EC2 Tags
plugin: aws_ec2
regions:
- us-west-2
keyed_groups:
- key: tags.TG
prefix: tag_TG_
separator: ""
compose:
# set the ansible_host variable to connect with the private IP address without changing the hostname
ansible_host: private_ip_address
aws ec2 describe-instances --region us-west-2 --instance-ids `curl -s http://169.254.169.254/latest/meta-data/instance-id` | jq '.Reservations[0].Instances[0].Tags | from_entries.TG'
$ ansible -i demo2.aws_ec2.yml tag_TG_Jim1 -m ping
ec2-54-187-132-73.us-west-2.compute.amazonaws.com | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
ec2-52-40-49-101.us-west-2.compute.amazonaws.com | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
ec2-34-220-218-167.us-west-2.compute.amazonaws.com | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
ec2-34-212-179-98.us-west-2.compute.amazonaws.com | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment