【问题标题】:Ansible, list object has no attributeAnsible,列表对象没有属性
【发布时间】: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


    【解决方案1】:

    使用with_items 代替with_nested

    【讨论】:

    • 这是我的问题的摘要版本。我真正想做的是调用一个端点来加密我的密码,但我认为它不一定是更多的代码。是的,它是我代码的另一部分的复制粘贴。
    【解决方案2】:

    我认为你想要loops and includes,因为你得到了一个预期的扁平列表(根据文档)。

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 2017-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 2021-05-25
      • 2022-01-20
      相关资源
      最近更新 更多