# Create hash variable in playbook for use by with\_dict

**URL:** <https://forum.ansible.com/t/create-hash-variable-in-playbook-for-use-by-with-dict/19779>\
**Category:** Ansible Project\
**Created:** [November 16, 2015, 11:38pm UTC](https://forum.ansible.com/t/create-hash-variable-in-playbook-for-use-by-with-dict/19779 "2015-11-16T23:38:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derek\_Olsen](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@Derek\_Olsen](https://forum.ansible.com/u/Derek_Olsen)\
**Post date:** [November 16, 2015, 11:38pm UTC](https://forum.ansible.com/t/create-hash-variable-in-playbook-for-use-by-with-dict/19779/1 "2015-11-16T23:38:07Z")

</div>

I’m hoping someone can help me learn how to work with ansible to achieve the following. This is my first forray into ansible (1.9.4). I

I am assigning a list variable called ‘datadog\_checks’ to different roles. Nodes which are in the etcd group would get the following ‘datadog\_checks’ variable.

datadog\_checks:

- etcd
- kubelet

Each datadog check has 2 file copies associated with it. The etcd check  
has the following file copies

etcd.py → /etc/dd-agent-container/checks.d/etcd.py  
etcd.yaml → /etc/dd-agent-container/conf.d/etcd.conf

This same pattern occurs for every check in the datadog\_checks list. I was hoping to dynamically create a hash based on the datadog\_checks list like this.

datadog\_checks\_hash =   
for x in datadog\_checks:  
datadog\_checks\_hash.append({ ‘file’ : x + ‘.py’, ‘path’ : ‘/etc/dd-agent-container/checks.d’})  
datadog\_checks\_hash.append({ ‘file’ : x + ‘.yaml’, ‘path’ : ‘/etc/dd-agent-container/conf.d’})

And then iterate over the hash like this

- name: create datadog checks  
copy: src=“{{ item.file}}” dest=“{{ item.path}}{{ item.file}}” mode=0644  
with\_dict: “{{ datadog\_checks\_hash }}”

I’m stuck trying to figure out what my options are for creating the datadog\_checks\_hash. From what i’ve read I can’t do this in the playbook itself. Is this suited for doing in a jinja template?

Any pointers or ideas appreciated.
