Hi,

I'm trying to create a batch of json files, that will pull values from an 
inventory group.

Ideally, what I would like to have happen is 10 different files are created 
(the inventory group has 10 nodes in it), using both the position of the 
node in the inventory list and the fqdn of the node as the values that are 
populated into these json files. 

At this point, what I'm not sure how to do it create 10 separate files (I 
can create one big one), which uses the aforementioned values.

My template (this is what generates the one big file:

{% for node in groups['yarn-nms'] %}
{
    "instanceId": "{{ loop.index }}",
    "name": "yarn-nm",
    "cluster": "stg",
    "image": "{{ image }}",
    "instance": {
      "cpu": 24,
      "mem": 80000
    },
    "constraints": [[ "hostname", "CLUSTER", "{{ node }}" ]]
}
{% endfor %}


I tried stuffing that loop into the task that creates the json files:

---
- name: Make directory for json blobs
  file:
    path: ~/blobs
    state: directory

- name: Create json blobs
  template:
    src: pin-nm.json.j2
    dest: ~/blobs/pin-nm{% for node in groups['yarn-nms'] %}{{ loop.index }}{% 
endfor %}.json


but instead of giving me 10 different files, it gave me one file named 
pin-nm12345678910.json. And not surprisingly, the template didn't inherit 
any values.

Can anyone offer any suggestions on how to create the 10 separate files, 
with the values passed through to the templates? Or even just how to create 
a loop that creates the 10 different files - I'm pretty sure I could figure 
it out from there.

Thanks, 

AP

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e9581842-a4b2-4798-acd3-c02a35e3b5b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to