Hello, 

I am new learner, trying to get hands on inclusions, where I am using 
include_vars & include, however playbook execution is falling with  an 
undefined variable error.

[user@node0101 veriable_include]$ ansible-playbook -i inventory 
myplaybook.yml
PLAY [Install Some Package] 
********************************************************************************************************************************************
TASK [Gathering Facts] 
*************************************************************************************************************************************************
ok: [node0102]
TASK [include variables from varPackage.yml] 
***************************************************************************************************************************
ok: [node0102]
TASK [Install {{ vars.package }} package] 
******************************************************************************************************************************
fatal: [node0102]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 'dict object' has no attribute 
'package'\n\nThe error appears to be in 
'/home/user/veriable_include/tasks.yml': line 2, column 3, but may\nbe 
elsewhere in the file depending on the exact syntax problem.\n\nThe 
offending line appears to be:\n\n---\n- name: Install {{ vars.package }} 
package\n  ^ here\nWe could be wrong, but this one looks like it might be 
an issue with\nmissing quotes. Always quote template expression brackets 
when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo 
}}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}
PLAY RECAP 
*************************************************************************************************************************************************************
node0102                   : ok=2    changed=0    unreachable=0    
failed=1    skipped=0    rescued=0    ignored=0
[user@node0101 veriable_include]$


[user@node0101 veriable_include]$ pwd
/home/user/veriable_include

[user@node0101 veriable_include]$ ls -l
total 20
-rw-rw-r--. 1 user user  93 Apr 25 17:57 ansible.cfg
-rw-rw-r--. 1 user user  24 Apr 25 16:31 inventory
-rw-rw-r--. 1 user user 208 Apr 26 02:51 myplaybook.yml
-rw-rw-r--. 1 user user 247 Apr 26 02:51 tasks.yml
-rw-rw-r--. 1 user user  71 Apr 26 02:52 varPackage.yml


*Following are the yml files & playbooks content:*

[user@node0101 veriable_include]$ *cat varPackage.yml*
---
vars:
 package: samba
 service: smb
 state: started
 enabled: true

[user@node0101 veriable_include]$ *cat tasks.yml*
---
- name: Install {{ vars.package }} package
  yum:
   name: "{{ vars.package }}"
   state: latest
- name: Start {{ vars.service }} service
  service:
   name: "{{ vars.service }}"
   state: "{{ vars.state }}"
   enabled: "{{ vars.enabled }}"

[user@node0101 veriable_include]$ *cat myplaybook.yml*
---
- name: Install Some Package
  hosts: node0102
  tasks:
  - name: include variables from varPackage.yml
    include_vars: varPackage.yml
  - name: include tasks from tasks.yml
    include: tasks.yml
...
[user@node0101 veriable_include]$


Please advice ...

---
*Kind Regards*
~Mitesh

-- 
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/383a093b-cd48-4e00-95e1-f2535f083e5d%40googlegroups.com.

Reply via email to