Ansible Local connection script argument path failed to detect

501 Views Asked by At

I have a ansible playbook which calls 2 roles. role 1 runs on local, which has a script with arg as file path /tmp/inputfile/input.csv. The playbook looks:

- hosts: "{{my_extra_var_IP}}"
  connection: local
  roles:
   - prereq

Roles task:

- name: Copy script to local
  copy:
   src: files/csv_to_files.sh
   dest: /tmp/input_dir/
   mode: 0777

- command: ls -ltr /tmp/input_dir

- command: cat /tmp/input_dir/inputFile.csv

#- name: run csv to yml script
#  script: /tmp/input_dir/csv_to_files.sh /tmp/input_dir/inputFile.csv
#  become_user: niceha

The output of first 2 tasks is success and is as expected but on 3rd & 4th step I get error:

FAILED! => {"changed": true, "cmd": ["cat", "/tmp/input_dir/inputFile.csv"], "delta": "0:00:00.007141", "end": "2017-06-09 15:53:58.673450", "failed": true, "rc": 1, "start": "2017-06-09 15:53:58.666309", "stderr": "cat: /tmp/input_dir/inputFile.csv: No such file or directory", "stdout": "", "stdout_lines": [], "warnings": []}

I am running this job from tower which uses userA I also tried to change the users but no luck.

2

There are 2 best solutions below

2
Jack On

The indenting does not look right:

- name: Copy script to local
  copy:
     src: files/csv_to_files.sh
     dest: /tmp/input_dir/
     mode: 0777
0
Niceha On

Ok. So after much reading I got to know the code is fine as it runs from the console but not from the Ansible tower, and just to cross check it worked from other dir paths. Ansible tower actually uses /tmp/ dir as staging area so any changes/tasks mentioned in the playbook to be run in tmp dir wont take affect.

Changing my input file path from /tmp to /home/user did the work for me.