Skip to content

Instantly share code, notes, and snippets.

@overdrive3000
Last active August 30, 2015 07:44
Show Gist options
  • Save overdrive3000/77939dccd01af4274bea to your computer and use it in GitHub Desktop.
Save overdrive3000/77939dccd01af4274bea to your computer and use it in GitHub Desktop.
Validate an EC2 instance by tag with Ansible
---
- hosts: localhost
tasks:
- name: Gather facts
action: ec2_facts
register: ami_id
- name: Print AMI ID
debug: msg={{ ami_id['ansible_facts']['ansible_ec2_instance_id'] }}
- name: Get tags
ec2_tag: resource={{ ami_id['ansible_facts']['ansible_ec2_instance_id'] }} region=us-west-2 state=list
register: role
- name: Validate role
debug: msg="This is a staging server"
when: role['tags']['env'] == 'staging'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment