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] <javascript:>> 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/6bfd7b08-4f97-49d7-abcf-2116d57ef274%40googlegroups.com.