Ansible Playbook中的'dict object'没有属性'stdout'

时间:2018-12-24 15:00:06

标签: ansible ansible-2.x ansible-facts ansible-template

我的剧本:

- name: JBoss KeyStore and Truststore passwords will be stored in the          password vault
    #shell: less "{{ vault }}"
     shell: cat "{{ vault }}"
    register: vault_contents
    tags:
      - BW.6.1.1.10
    with_items:
      - "{{ vault }}"
  - debug:
       msg: "JBoss config filedoes not contains the word vault"
    when: vault_contents.stdout.find('$VAULT') == -1

我正在尝试使用Jinga2模板通过ansible读取多个文件,并将输出解析为stdout并搜索关键字并进行报告。

它失败并显示以下错误:

TASK [testing_roles : debug]   **************************************************************************.   *****************************************************************
fatal: [d84e4fe137f4]: FAILED! => {"failed": true, "msg": "The conditional check 'vault_contents.stdout.find('$VAULT') == -1' failed. 
The error was: error while evaluating conditional (vault_contents.stdout.find('$VAULT') == -1): 'dict object' has no attribute 'stdout'\n\nThe error appears to have been in '/Ansible/Ansible/Relearn/testing_roles/roles/testing_roles/tasks/main.yml': line 49, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n      - \"{{ vault }}\"\n  - debug:\n    ^ here\n"}
to retry, use: --limit @/Ansible/Ansible/Relearn/testing_roles/playbook.retry

当我在其上附加单个文件条目时,它可以按预期工作,但是当更改为一系列文件时,它将失败。

这是在Ansible中扫描多个文件的正确方法,还是应该使用其他模块或方法。

非常感谢您的帮助。

在vars文件中,它具有以下内容:

vault:
  - /jboss-as-7.1.1.Final/standalone/configuration/standalone-full-ha.xml

谢谢

1 个答案:

答案 0 :(得分:2)

- debug: var=vault_contents的一次细微检查会显示出,当与with_items:之类的循环结构一起使用时,寄存器变量具有一个list的名称为results,其中包含结果对于循环的每次迭代。 the fine manual

中也清楚记录了此内容

所以,您可能想要的是:

- debug:
    msg: "JBoss config {{ item.item }} does not contain the word vault"
  when: item.stdout.find('$VAULT') == -1
  with_items: '{{ vault_contents.results }}'
相关问题