我用分子来测试角色。任务是使用变量的复制模板。
ansible /任务/main.yml
---
- name: copy manifest billing
template:
src: templates/service.j2
dest: "{{ item }}"
with_items:
"{{ services }}"
ansible / vars / main.yml
services:
- billing
- cart
- checkout
当我运行“分子收敛”时,出现错误
TASK [ansible : copy manifest billing] *****************************************
fatal: [instance]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to be in '/home/user/ansible/tasks/main.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: copy manifest billing\n ^ here\n"}
问:“错误是:'item'未定义”
答:缩进是错误的。with_items
不是模块的参数。这是循环模块的指令。正确的语法是
---
- name: copy manifest billing
template:
src: templates/service.j2
dest: "{{ item }}"
with_items:
"{{ services }}"
笔记
with_items: "{{ services }}"
loop: "{{ services }}"
ansible-playbook playbook.yml --check
。该命令不会抱怨"Invalid options for template: with_items"
!但是使用模块debug
检查可以按预期进行 - debug:
var: item
with_items:
"{{ services }}"
fatal: [localhost]: FAILED! => {"msg": "Invalid options for debug: with_items"}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句