尝试使用 ansible 运行 python 脚本时出错

Getting error when trying to run python script using ansible

- name: Create directory for python files
  file: path=/home/vuser/test/
    state=directory
    owner={{ user }}
    group={{ user }}
    mode=755

- name: Copy python file over
  copy:
    src=sample.py
    dest=/home/vuser/test/sample.py
    owner={{ user }}
    group={{ user }}
    mode=777

- name: Execute script
  command: python sample.py
  args:
  chdir: /home/vuser/test/
  ignore_errors: yes

错误 致命的:[n]:失败! => {"changed": true, "cmd": ["python", "sample.py"], "delta": "0:00:00.003200", "end" : "2019-07-18 13:57:40.213252", "msg": "non-zero return code", "rc": 1, "start": "2019-07-18 13:57:40.221132", "stderr": "", "stderr_lines": [], "stdout": "1", "stdout_lines": ["1"]}

想不通,不胜感激

像下面这样更改缩进并删除 ignore_errors。

- name: Execute script
  command: python sample.py
  args:
     chdir: /home/vuser/test/
  register: cat_contents

- name: Print contents
  debug:
     msg: "{{ cat_contents.stdout }}"
- name: Create directory for python files
  file: path=/home/vuser/test/
    state=directory
    owner={{ user }}
    group={{ user }}
    mode=755

- name: Copy python file over
  copy:
    src=/home/vuser/sample.py
    dest=/home/vuser/test/
    owner={{ user }}
    group={{ user }}
    mode=777

- name: Execute script
  command: python sample.py
  args:
     chdir: /home/vuser/test/

sample.py 已正确复制到位于 dest=/home/vuser/test/ 的节点 1 的目标文件夹中 但是我在完成更改后也收到此错误

致命:[node1]:失败! => {"changed": true, "cmd": ["python", "sample.py"], "delta": "0:00:00.002113", "end" : "2019-07-19 10:59:53.7535351", "msg": "non-zero return code", "rc": 1, "start": "2019-07-19 10:59:53.358678548", "stderr": "", "stderr_lines": [], "stdout": "hello world", "stdout_lines": ["hello world"] }