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

error fatal: [n]: FAILED! => {"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"]}

not able to figure out, help would be appreciated

user583088
  • 989
  • 1
  • 6
  • 10
  • Are you sure your `sample.py` script doesn't produce any errors? – vrdrv Jul 18 '19 at 21:14
  • yes no errors, did run the file on the node once it is copied using python sample.py . sample.py has just printf statement – user583088 Jul 18 '19 at 21:15
  • Try to change `ignore_errors: yes` to `ignore_errors: True` and remove the empty `args:`. – vrdrv Jul 18 '19 at 21:20
  • I have already removed ignore_errors: yes but if I remove args then I get errorERROR! 'chdir' is not a valid attribute for a Task – user583088 Jul 18 '19 at 21:25
  • I see. `chdir: /home/vuser/test/` is supposed to be under `args`. You have to indent that line. – vrdrv Jul 18 '19 at 21:29
  • indent did not change the error - name: Execute script command: python sample.py args: chdir: /home/vuser/test/ – user583088 Jul 18 '19 at 21:36
  • @user583088: vrdrv is right. chdir must be indented. This was the reason of the error: `ERROR! 'chdir' is not a valid attribute for a Task`. You claim `indent did not change the error`?! You should make the question current. I downvoted. – Vladimir Botka Jul 19 '19 at 02:20
  • I am not sure how to make that issue current , but I have added the changed code and the error in answer for better visibility . so that I can get this issue resolved – user583088 Jul 19 '19 at 18:08

2 Answers2

1

Change the indent like below and remove 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 }}"
Prakash Krishna
  • 1,239
  • 6
  • 12
0
- 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/

The sample.py is copied correctly in the destination folder at the node1 at dest=/home/vuser/test/ but the I get this error after I have done the change also

fatal: [node1]: FAILED! => {"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"]}

user583088
  • 989
  • 1
  • 6
  • 10