{% for item in groups['docker_servers']-%}
{{ hostvars[item]['ansible_default_ipv4']['address'] }}
{% endfor %}
- name: Configure pg_hba template: src: test.txt.j2 dest:
/tmp/groups.txt tags:
- install_docker
[root@worker-server ~]# cat /tmp/groups.txt 10.5.0.15
Here it works, but on another environment it gives error
Version is 2.9.9
teisipäev, 2. juuni 2020 13:33.02 UTC+3 kirjutas Arko Köst:
>
> I've found a working one, it does work on another cluster, but doesn't
> work in my environment.
>
> Template:
> {% for item in groups['nodes']-%}
> {{ hostvars[item]['ansible_default_ipv4']['address'] }}
> {% endfor %}
>
> - hosts: opmon
> tasks:
> - name: Configure pg_hba
> template:
> src: test.j2
> dest: /tmp/groups.txt
>
> It works on another environment, but in my environment it goes fatal:
> [xroad-a.itarchive.home]: FAILED! => {"changed": false, "msg":
> "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has
> no attribute 'ansible_default_ipv4'"}
>
> teisipäev, 2. juuni 2020 13:28.10 UTC+3 kirjutas Vladimir Botka:
>>
>> On Tue, 2 Jun 2020 02:45:41 -0700 (PDT)
>> Arko Köst <[email protected]> wrote:
>>
>> > ... get ip addresses of hosts in specific group
>> > - hosts: opmon
>> >
>> > I need, that node1.itarchive.home will be in IP
>> > Something like that:
>> > host 'op-monitor' opmonitor 192.168.0.95/24 md5'
>>
>> As a hint, try "template"
>>
>> shell> cat pg_hba.conf.j2
>> {% for host in groups['opmon'] %}
>> host {{ host }} opmonitor {{
>> hostvars[host]['ansible_all_ipv4_addresses'] }}
>> {% endfor %}
>>
>> and playbook
>>
>> shell> cat pb.yml
>> - hosts: opmon
>> gather_facts: true
>> tasks:
>> - template:
>> src: pg_hba.conf.j2
>> dest: /tmp/pg_hba.conf
>> delegate_to: localhost
>> run_once: true
>>
>> Take a look at the facts collected by "setup" and fit the template to
>> your
>> needs. See what facts are available
>>
>> shell> ansible remote_host -m setup
>>
>> HTH,
>>
>> -vlado
>>
>> --
>> Vladimir Botka
>>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/44852db7-73f9-4c8c-82c7-76071eb3cedb%40googlegroups.com.