On Saturday, 24 November 2018 20:10:19 CET Nick Ellson wrote:
>
> I have a task that I am scratching my head on, and my google foo is just
> getting some really basic examples of the COPY - CONTENT method of writing
> a file.
>
> my variable returned from the URI module is data, which is a 4 variable
> JSON array. data.json.devices is the list I want to dump to a file to use
> as my future hosts file for cli config operations.
>
> ok: [localhost] => {
> "msg": [
> {
> "hostname": "host1",
> "id": "0093253e",
> "mgmtIP": "10.10.10.1"
> },
> {
> "hostname": "host2",
> "id": "00e75962",
> "mgmtIP": "10.10.10.8"
> },
> <snip the other 378 entries in list>
>
> I'd like to spit this to a ./inventory/hosts file in a format that my
> playbook can then use in the next set of tasks. So just the "hostname" and
> "mgmtIP" variables written to a line.
>
> How might that look?
You can use the template or the copy module, the jinja template code is the
same in both so i just show the copy module
- name: Create inventory
copy:
content: |
{% for i in data.json.devices %}
{{ i.hostname }} ansible_host={{ i.mgmtIP }}
{% endfor %}
dest: inventory/hosts
--
Kai Stian Olstad
--
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/5068187.qNy6Gv2Atm%40x1.
For more options, visit https://groups.google.com/d/optout.