Dynamic vars generation, overriding community roles' tasks, wrapper playbooks

61 views
Skip to first unread message

Vladimir Sol

unread,
Jan 28, 2015, 2:42:38 AM1/28/15
to ansible...@googlegroups.com
Hi everyone, first of all, I'm new to Ansible and come from Chef background, so any Chef parallels are welcome. I also use the official ec2 dynamic inventory.

To the problems. 

1. So, thanks to the ec2 inventory, I have "ec2_tag_Name", "ec2_public_dns_name" in hostvars. I'm leveraging a role from ansible-galaxy that expects a hosts variable to be an array of dicts with keys 'name', 'address', 'extra' that would look something like this for a static infrastructure:

hosts:
 
- name: server1
    address
: ec2-addr1.amazonaws.com
    extra
:
     
- a string

As you might have expected, the hosts come and go, I use an ec2 tag to group them, say "tag_group_one", on top of that, the extra array is always the same. So I would like to have my hosts variable to be dynamically generated on each playbook run, something like this:

hosts: {{ [{"name": host["ec2_tag_Name"], "address": host["ec2_public_dns_name"], "extra": ["a string"]} for host in map(hostvars, groups["tag_group_one"])] }}

Sorry for the long oneliner, but the idea behind it is simple, just reshape one variable structure into another, so the community role could process it appropriately. I also know that isn't valid jinja2 which is disappointing in it's own regard.

What would be the simplest (and the right) solution for this?

2. After that I looked into the community role I'm using, and realized that this list variable is only used for rendering a single template. This posed two questions: is there a precedence mechanism for templates? (Chef would first lookup templates with the same name in the caller cookbook) And, is there a way to override an argument of a specific task in an included role? Like replacing the src argument in the template rendering task.

3. This would be a little bug report / feature request: wildcard host patterns don't work with groups function (tried that in a template).

I ended up forking the community role and making the template use hostvars directly.
Reply all
Reply to author
Forward
0 new messages