代码之家  ›  专栏  ›  技术社区  ›  D. Seah

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

  •  0
  • D. Seah  · 技术社区  · 4 年前

    对于这样的测试我有一个可靠的剧本

    ---
    - 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
    

    import sys
    
    with open("/tmp/workfile", "w") as f:
        f.write(sys.argv[1])
    

    执行playbook并查看/tmp/workfile,我得到

    [Errno
    

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

    1 回复  |  直到 4 年前
        1
  •  1
  •   larsks    4 年前

    ---
    - 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"
        ]
    }