-1

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.

Niceha
  • 384
  • 2
  • 12
  • 1
    I see no reason for the `cat /tmp/input_dir/inputFile.csv` command to work, based on the code you posted in the question. You don't create that file so it does not exist. It's obvious. – techraf Jun 10 '17 at 00:28

2 Answers2

0

The indenting does not look right:

- name: Copy script to local
  copy:
     src: files/csv_to_files.sh
     dest: /tmp/input_dir/
     mode: 0777
Jack
  • 5,801
  • 1
  • 15
  • 20
  • Indentation got like this while pasting in stackoverflow otherwise evrything syntax wise is correct. I am running the playbook from Ansible-tower server then only it gives error. Same playbook if I run from server console it runs fine. – Niceha Jun 09 '17 at 22:38
  • OK -- how 'bout you fix the indents in the post, and I'll delete my answer! – Jack Jun 09 '17 at 22:39
0

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.

Niceha
  • 384
  • 2
  • 12