I am using AWS CloudFormation to create infrastructure and the template creates EC2 instances, Elasticache cluster and RDS instance. Now, I am wondering as to how to use the CloudFormation outputs to create Ansible Dynamic Inventory? In the static inventory files I also have groups of groups. How do I tweak my ec2.ini and ec2.py to accomodate the same?
I have the same question. Why there isn’t any answer here?
Just a quick response, some what self promoting but hopefully helpful.
https://github.com/ansible/ansible-modules-extras/pull/2329
cloudformation_facts module
I’d previously put together a lookup plugin (mainly through combining others efforts)
https://github.com/ansible/ansible/pull/12880
I’m going to make the time to rewrite this using boto3 and try and get it completed before the end of July.
This will give you the resources that were created by the cloudformation stacks. It’s also possible to use the ec2_facts, http://docs.ansible.com/ansible/ec2_facts_module.html and ec2_remote_facts http://docs.ansible.com/ansible/ec2_remote_facts_module.html to get a list of the ec2 instances and then iterate them through through the add_host http://docs.ansible.com/ansible/add_host_module.html to add them to an in-memory inventory.
Similar to the example here, http://docs.ansible.com/ansible/ec2_module.html#examples