Please refer to the attached file for issues I am running into...


*Here is my playbook:*

--- # Ansible facts example

- hosts: centos

 tasks:

     - name: create a file to write the fact values

      lineinfile:

          path: /home/ansible/hostname

          create: yes

          line: "{{ ansible_hostname }}"

     - name: access magic variables

      lineinfile:

          path: /home/ansible/hostname

          line: "{{ hostvars['centos']['ansible_default_ipv4']['address'] 
}}"

 

*And here is the command I am using to run it:*

ansible-playbook -i inv facts.yml 

 

*And here is the inventory (host):*

[centos]

cen ansible_host=172.31.4.215

 

*I keep running into this error:*

 

PLAY [centos] 
********************************************************************

TASK [Gathering Facts] 
***********************************************************

ok: [cen]

TASK [create a file to write the fact values] 
************************************

ok: [cen]

TASK [access magic variables] 
****************************************************

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"}

to retry, use: --limit @/home/ansible/facts.retry

PLAY RECAP

***********************************************************************

cen            : ok=2   changed=0  unreachable=0  failed=1  

 

*How to resolve this?*

 

-- 
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/b4e1237d-9f80-4fee-8b84-61116466c7db%40googlegroups.com.

Reply via email to