How to adapt tempfile to cfg

7 views
Skip to first unread message

Pierre Ochsenbein

unread,
Jul 8, 2019, 9:30:40 AM7/8/19
to ansible...@googlegroups.com
Hey guys,

I use the following template file .j2 to update config file on remote host.

Template file: pg_hba.conf.j2

{% for slave in groups['slaves'] %}
host    replication             {{ postgresql_streaming_user.name }}            {{ hostvars[slave]['ansible_all_ipv4_addresses'] }}/32          {{ postgresql_default_ipv4_auth_method }}
{% endfor %}


Configuration file: pg_hba.conf.j2
host    database             user         [u'10.123.214.7']/32            md5

How I can adapt my template file to remove this character in my configuration file [u' …..  '] ?

Thanks in advance.

Kai Stian Olstad

unread,
Jul 8, 2019, 10:55:04 AM7/8/19
to ansible...@googlegroups.com
On 08.07.2019 15:30, Pierre Ochsenbein wrote:
> *Template file: pg_hba.conf.j2*
>
> {% for slave in groups['slaves'] %}
> host replication {{ postgresql_streaming_user.name
> }} {{ hostvars[slave]*['ansible_all_ipv4_addresses']*
> }}/32 {{ postgresql_default_ipv4_auth_method }}
> {% endfor %}
>
>
> *Configuration file: pg_hba.conf.j2*
> host database user * [u'*10.123.214.7*']*/32
> md5
>
> How I can adapt my template file to remove this character in my
> configuration file *[u' ….. **'] ?*

If the server just have one IP you probably should use
ansible_default_ipv4.address instead if ansible_all_ipv4_addresses.

If the server have multiple IP that you would like to include you would need to loop over ansible_all_ipv4_addresses since it is a list of all IP on the server.


--
Kai Stian Olstad

Pierre Ochsenbein

unread,
Jul 8, 2019, 11:36:47 AM7/8/19
to ansible...@googlegroups.com
Solution looks like this : ['ansible_default_ipv4']['address']



--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c4517515-6ca1-91af-c7e8-3b6c590e4040%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


--
Cordialement,

Pierre Ochsenbein
Mobile: +33668295394
Reply all
Reply to author
Forward
0 new messages