fatal: [cen]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: "hostvars[‘centos’]" is undefined\n\nThe error appears to have been in ‘/home/ansible/facts.yml’: line 9, column 13, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n line: "{{ ansible_hostname }}"\n - name: access magic variables\n ^ here\n”}
I don’t see attached files (which is good I’d say) but then the indentation of the include yaml files is a bit messed up.
Regardless of that, it is not clear what you are trying to do with this playbook?
Write the default ipv4 address of all hosts in a group to a file on all those hosts?
Please explain what you want to do, and why (as there may be alternative way to achieve what you want).
Hello -
I am trying to create a new file called 'hostname", and within it trying to copy the ansible_hostname, and ipv4 address using the hostvars magic variable.
Attaching the screenshots.
This is part of the training module I am currently learning, to try how the magic variables work.
the centos is group, with one host, in the inventory file.
the output of this playbook is supposed to be a file named “hostname” gets created on target host. And it should have two values: “ansible_hostname”, and the “ipv4” address.