我在剧本中尝试include_vars
,但我想排除一个文件并包含其余部分。尝试ignore_files: 'b.yml'
但它删除了包括所有文件的文件时没有加载任何文件。
# 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
#
查看include vars输出,没有加载任何文件。
# 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
答案 0 :(得分:1)
始终检查参数类型:
- ignore_files
List of file names to ignore.
[Default: None]
version_added: 2.2
将您的arg更改为列表:
- include_vars:
dir: 'myvars'
ignore_files: ['b.yml']
extensions: ['yml']