Hi all,
Below is my playbook.
- name: Create server list
hosts: all
become: true
become_user: root
gather_facts: yes
tasks:
- name: Copy the template
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 %}
When I run the playbook, I get the below error message.
TASK [Copy the template]
*******************************************************************************************************************************************************************************************************************
skipping: [ansible4.example.com]
skipping: [ansible3.example.com]
fatal: [ansible2.example.com]: FAILED! => {"changed": false, "msg":
"AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has
no attribute 'ansible_fqdn'"}
Could someone help if there is anything wrong with my playbook.
Thanks,
Rajesh
--
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/0e8ec2bb-9f04-4505-9863-41116b03fb2e%40googlegroups.com.