On Mon, 30 Mar 2020 19:28:13 -0700 (PDT) Rajesh <[email protected]> wrote:
> - hosts: all
> [...]
> template:
> src: templates/server_list.j2
> dest: /etc/server_list.txt
> owner: automation
> mode: '0600'
> setype: net_conf_t
> when: ansible_fqdn in groups['proxy']
>
> [automation@workstation plays]$ cat templates/server_list.j2
> {% for host in groups['all'] %}
> {{ hostvars[host]['ansible_fqdn'] }}
> {% endfor %}
> [...]
> fatal: [ansible2.example.com]: FAILED! => {"changed": false, "msg":
> "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has
> no attribute 'ansible_fqdn'"}
Your playbook works for me. The problem is missing variable "ansible_fqdn" at
some host. You might want to find the host and see what's the problem. Try
- hosts: all
tasks:
- debug:
var: ansible_fqdn
Why do you use "ansible_fqdn" in the "when" condition instead of
"inventory_hostname"? This implicates that you're mixing "ansible_fqdn" and
"inventory_hostname" in the inventory.
HTH,
-vlado
--
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/20200331082145.1e7174e4%40gmail.com.
pgpT9CtwXdnrz.pgp
Description: OpenPGP digital signature
