Create hash variable in playbook for use by with_dict

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.