ansible:我没有得到任务的全部错误消息

ansible:我没有得到任务的全部错误消息,ansible,Ansible,我有一本类似这样的测试手册 --- - name: "test" hosts: localhost tasks: - name: "list files" block: - name: "list files" command: /usr/bin/example-command -x -y -z register: output resc

我有一本类似这样的测试手册

---
- name: "test"
  hosts: localhost

  tasks:
    - name: "list files"
      block:
        - name: "list files"
          command: /usr/bin/example-command -x -y -z
          register: output

      rescue:
        - script: test.py {{ output.msg }}
          args:
            executable: python3
它将失败,我想捕获错误消息并将其发送到python脚本test.py(现在,我只是将消息写入一个文件)

导入系统 将open(“/tmp/workfile”,“w”)作为f: f、 写入(sys.argv[1]) 执行playbook并查看/tmp/workfile,我得到

[Errno
为什么我没有得到完整的错误信息


谢谢

你需要引用你的脚本中的参数。考虑下面的剧本:

---
- name: test
  hosts: localhost
  gather_facts: false
  vars:
    output:
      msg: This is a test.
  tasks:
    - script: test.py {{ output.msg }}
      args:
        executable: python3
      register: script1

    - script: test.py "{{ output.msg }}"
      args:
        executable: python3
      register: script2

    - debug:
        msg:
          - "{{ script1.stdout }}"
          - "{{ script2.stdout }}"
其中,
test.py
只是:

import sys

print('argv[1]: ', sys.argv[1])
最终任务输出:

TASK [debug] *********************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "argv[1]:  This\n",
        "argv[1]:  This is a test.\n"
    ]
}