【发布时间】:2017-12-15 11:58:00
【问题描述】:
我正在使用 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
我的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 不考虑行 o regexp 的内容。我一直在做测试,用于初始化行和正则表达式的变量不为空。
【问题讨论】:
标签: ansible ansible-2.x