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

**URL:** <https://forum.ansible.com/t/dynamic-vars-generation-overriding-community-roles-tasks-wrapper-playbooks/17390>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [January 28, 2015, 7:42am UTC](https://forum.ansible.com/t/dynamic-vars-generation-overriding-community-roles-tasks-wrapper-playbooks/17390 "2015-01-28T07:42:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir\_Sol](https://avatars.discourse-cdn.com/v4/letter/v/43a26b/32.png) [@Vladimir\_Sol](https://forum.ansible.com/u/Vladimir_Sol)\
**Post date:** [January 28, 2015, 7:42am UTC](https://forum.ansible.com/t/dynamic-vars-generation-overriding-community-roles-tasks-wrapper-playbooks/17390/1 "2015-01-28T07:42:38Z")

</div>

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](http://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?

1. 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.

2. 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.
