Ansible CloudFormation Lookup Plugin
As the Ansible/AWS investigations continue I had the need to lookup outputs from existing CloudFormation stacks. I spent ten minutes reading through the existing lookup plugins and came up with the Ansible CloudFormation Lookup Plugin.
I’m not sure this is going to be our final solution. Michael DeHaan suggested that moving to a fact plugin might be better in terms of cleaner usage and easier testing, so I’m at the least going to implement a trial version of that. I was quite surprised at how easy writing an Ansible lookup plugin was though, even for someone with my limited python skills.
Once you’ve downloaded and installed the plugin, using it in your templates is as simple as
{{ lookup('cloudformation', 'region/stackname/output/outputname') }}
# and an actual example:
{{ lookup('cloudformation', 'eu-west-1/unixdaemon-natinstance/output/nat_group_id') }}
It uses boto under the covers and expects to find your credentials as environmental variables. This is only a tiny chunk of code but it’s allowed us to continue on with the evaluations while gaining a little more comfort in our ability to extend Ansible to suit our needs.