【发布时间】:2017-02-05 09:46:56
【问题描述】:
我有以下问题:
当我使用变量 with_subelements 时出现错误:错误!子元素查找需要字典,得到 'incor'
我的主机文件:
[incor]
127.0.0.1
目录组变量
group_vars
--- all
--- incor
--- main.yml
group_vars/incor/main.yml
---
incor:
- pfileurl: "http://domain/file1.jar"
pfilename: "user1.jar"
pfiletype: "lib"
pfileset:
- {type: "type1", reg: "reg1" }
- {type: "type2", reg: "reg2" }
- pfileurl: "http://domain/file2.jar"
pfilename: "user2.jar"
pfiletype: "lib"
pfileset:
- {type: "type1", reg: "reg1" }
- {type: "type2", reg: "reg2" }
roles/p_get_file/tasks/main.yml
- name: Download files
get_url:
url="{{ item.0.pfileurl }}"
dest="{{ path }}{{ item.1.type }}/{{ item.1.reg }}/{{ item.0.pfilename }}"
force="yes"
with_subelements:
- "{{ projectname }}"
- "pfileset"
when: "'item.0.pfiletype is defined' and item.0.pfiletype == 'lib'"
delegate_to: "127.0.0.1"
myplaybook.yml
- hosts: "{{ hosts }}"
roles:
- { role: p_get_file }
开始剧本
ansible-playbook myplaybook.yml --extra-vars "hosts='incor' projectname='incor'"
Ansible 1.9.4 中的变量 {{ projectname }} 存在问题,但它可以工作但 在 Ansible 2.2.1.0 中不起作用:错误!子元素查找需要一个字典,得到'incor'
【问题讨论】:
标签: ansible ansible-2.x