我正在使用Ansible 2.3.0.0并且我在Ansible 2.4.0.0中进行了测试,获得了相同的结果。我的问题很简单,但我看不出问题。
我在Ansible中定义了一个对象列表,如下所示:
vars:
password_text_to_encrypt:
- { line: "{{truststore_pass }}" , regexp: '\${TRUSTSTORE_PASS}*'}
- { line: "{{ keystore_pass }}" , regexp: '\${KEYSTORE_PASS}*'}
- { line: "{{ gp_pass }}" , regexp: '\${GP_PASS}*'}
- { line: "{{ datasource_password }}" , regexp: '\${DATASOURCE_PASS}*'}
- { line: "{{ server_password }}" , regexp: '\${SERVER_PASSWORD}*'}
- { line: "{{ sftp_password }}" , regexp: '\${SFTP_PASSWORD}*'}
- { line: "{{ db_userpassword }}" , regexp: '\${DB_PASSWORD}*'}
roles:
- basic_role
My Basic_role只打印项目,我想获取每行的内容:
---
- name: "print password"
debug:
msg: "The content of the line is: {{ item.line}}"
with_nested:
- "{{password_text_to_encrypt}}"
但我获得的结果是:
FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'line'\n\nThe error appears to have been in.....
如果我将item.line
更改为item
,则可以正常显示:
ok: [localhost] => (item=[u'regexp', u'line']) => {
"item": [
"regexp",
"line"
],
"msg": "The content of the line is: [u'regexp', u'line']"
}
.
.
.
总而言之,Ansible不考虑line o regexp的内容。我一直在做测试,用于init line和regexp的变量不是空的。
答案 0 :(得分:1)
使用with_items
代替with_nested
。
答案 1 :(得分:-1)
我认为您需要loops and includes,因为您正在获得预期的扁平列表(根据文档)。