Reputation: 190
I am trying include_vars
in a playbook, But i want to exclude one file and include rest of them. Tried ignore_files: 'b.yml'
But it is not loading any files, when removed its including all files.
# tree
.
├── myvars
│ ├── a.yml
│ └── b.yml
└── test.yml
1 directory, 3 files
# cat test.yml
---
- hosts: all
tasks:
- include_vars:
dir: 'myvars'
ignore_files: 'b.yml'
extensions: ['yml']
- debug:
msg: "{{ name }}"
# cat myvars/a.yml
---
name: IronMan
#
see the include vars output, none of the file is loaded.
# ansible-playbook test.yml -i "localhost," -c local -vv
PLAYBOOK: test.yml ***************************************************************************************************************************
1 plays in test.yml
PLAY [all] ***********************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************
ok: [localhost]
META: ran handlers
TASK [include_vars] **************************************************************************************************************************
task path: /root/test.yml:4
ok: [localhost] => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "failed": false}
TASK [debug] *********************************************************************************************************************************
task path: /root/test.yml:9
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'name' is undefined\n\nThe error appears to have been in '/root/test.yml': line 9, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'name' is undefined"}
to retry, use: --limit @/root/test.retry
PLAY RECAP ***********************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1
Upvotes: 0
Views: 991
Reputation: 68269
Always check parameter type:
- ignore_files
List of file names to ignore.
[Default: None]
version_added: 2.2
Change your arg to be a list:
- include_vars:
dir: 'myvars'
ignore_files: ['b.yml']
extensions: ['yml']
Upvotes: 2