Created
March 29, 2016 13:24
-
-
Save MattSurabian/f20a63bdd910827f2a3f to your computer and use it in GitHub Desktop.
Revisions
-
MattSurabian created this gist
Mar 29, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ ### Setting Tags in Terraform Determine some sensible tags to pass non-critical information to Ansible or other CM solutions: ``` resource "aws_instance" "main" { ... tags { ... "some_tag" = "waka" } } ``` ### Limiting Playbooks via AWS Tags Make sure the dynamic inventory config file (`ec2.ini`) has at least the `group_by_tag_keys` option commented out ``` ... # The EC2 inventory output can become very large. To manage its size, # configure which groups should be created. # group_by_key_pair = True group_by_tag_keys = True ``` **At command runtime:** ``` ansible-playbook ... --limit tag_some_tag_Waka ``` **In the playbook:** ``` - hosts: tag_some_tag_Waka ``` ### Using EC2 Facts in a playbook with dynamic inventory ``` {{ec2_tag_some_tag}} ``` ### Using "EC2 Facts" in a playbook without dynamic inventory For this to work the instance must have the AWS CLI installed and have an IAM role assigned with the necessary permissions. ``` - name: get instance tags shell: aws ec2 describe-tags --filters="Name=resource-id,Values=$(ec2metadata --instance-id)" environment: AWS_DEFAULT_REGION: us-east-1 register: instance_data ```