On 04. aug. 2017 12:20, chbndrhnns wrote:
I have a setup with host1, host2, host3. I need to read a file into a
variable per server, pass it to a Jinja2 template and fill in values. Each
host should only get the values from the other two ones. I have no good
idea how to achieve this with Jinja2 syntax. Is somebody willing to help?
My code looks like this now. The do keywords seems not to be supported by
Ansible
- set_fact:
public_keys: >-
{% set me = inventory_hostname.split('host')[1] | int %}
{% for svr in groups.cluster|difference([me]) %}
{% do public_keys[svr] = {{ lookup('file', 'keys/' + svr +
‚.key.public') }} %}
{% endfor %}
- set_fact:
public_keys: |
{% for svr in groups.cluster|difference([inventory_hostname]) %}
{{ lookup('file', 'keys/' + svr + '.key.public') }} %}
{% endfor %}
Loop like this should do what you want.
But you might have som newline challenges to sort out.
--
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/f68dfcdf-9266-5248-4d8a-4c51cf80b74d%40olstad.com.
For more options, visit https://groups.google.com/d/optout.