# Adding dynamic keys and values as module attributes

**URL:** <https://forum.ansible.com/t/adding-dynamic-keys-and-values-as-module-attributes/25189>\
**Category:** Ansible Project\
**Created:** [August 6, 2017, 6:36pm UTC](https://forum.ansible.com/t/adding-dynamic-keys-and-values-as-module-attributes/25189 "2017-08-06T18:36:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://forum.ansible.com/u/Thomas)\
**Post date:** [August 6, 2017, 6:36pm UTC](https://forum.ansible.com/t/adding-dynamic-keys-and-values-as-module-attributes/25189/1 "2017-08-06T18:36:19Z")

</div>

Hi

Does anyone knows how it is possible to include all sub elements of a value to modules as attributes?

vars  
extra\_vars:  
function: “server”  
anotherkey: “anothervalue”  
ansible\_ssh\_private\_key\_file: “/home/someuser/.ssh/id\_rsa”

static task i have:

- name: “Create a group”  
add\_host:  
name: “{{ item.name }}”  
groups: “servergroup”  
ansible\_connection: ssh  
ansible\_host: “{{ item }}”  
ansible\_port: 22  
function: “server”  
anotherkey: “anothervalue”  
ansible\_ssh\_private\_key\_file: “/home/someuser/.ssh/id\_rsa”  
with\_items:
- “[host1.com](http://host1.com)”
- “[host2.com](http://host2.com)”
- “[host4.com](http://host4.com)”

dynamic task i want in a comination with “extra\_vars” :

- name: “Create a group”  
add\_host:  
name: “{{ item.name }}”  
groups: “servergroup”  
ansible\_connection: ssh  
ansible\_host: “{{ item }}”  
ansible\_port: 22  
{% for element in extra\_vars %}  
{{ “element.key”: “element.value” }}  
{% endfor %}  
with\_items:
- “[host1.com](http://host1.com)”
- “[host2.com](http://host2.com)”
- “[host4.com](http://host4.com)”

I hope you could understand my intention.

With nested loops I wasn’t successful. Maybe there is a possibility with a combine filter?

Thank you.
