On Wednesday, 29 November 2017 14.52.28 CET texas living wrote:
> loop code:
>
> ---
> servers:
> {% for item in csvfile.split("\n") %}
> {% if loop.index != 1 %}
> {% set list = item.split(",") %}
> {{ list[1]|trim() }}:
> Type: {{ list[0]|trim() }}
> Hostname: {{ list[1]|trim() }}
> IP_Address: {{ list[2]|trim() }}
> Gateway: {{ list[3]|trim() }}
> DNS_Server: {{ list[4]|trim() }}
> NTP_Server: {{ list[22]|trim() }}
> {% endif %}
> {% endfor %}
>
>
> Question I have is, how would I pull out loop.index. 1 and use the title
> names as variables? Something like this:
>
> {{ title. }}: {{ list[0]|trim() }}
> {{ title. }}: {{ list[1]|trim() }}
> {{ title }}: {{ list[2]|trim() }}
> {{ title }}: {{ list[3]|trim() }}
> {{ title }}: {{ list[4]|trim() }}
> {{ title }}: {{ list[22]|trim() }}
Can't you just do something like this?
{% if loop.index == 1 %}
{% set title = item.split(',') %}
{% endif %}
Then you can use title[0], title[1]...
--
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/1645951.JW1Z57P5mg%40x1.
For more options, visit https://groups.google.com/d/optout.