';dict对象';没有属性';stdout';在Ansible剧本中
我的剧本:';dict对象';没有属性';stdout';在Ansible剧本中,ansible,ansible-2.x,ansible-facts,ansible-template,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: - "{{ va
- 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
谢谢检查
-debug:var=vault\u contents
将向您显示,当与循环构造(如with\u items:
)一起使用时,寄存器变量有一个名为results
的列表,其中包含循环每次迭代的结果。这一点也记录在中
因此,您想要的可能是:
- debug:
msg: "JBoss config {{ item.item }} does not contain the word vault"
when: item.stdout.find('$VAULT') == -1
with_items: '{{ vault_contents.results }}'
谢谢,是的,我错过了完整的文档阅读手册是为其他人准备的。