Resolution Resolution Problem

I have a simple task that creates a file:

- name: create fake file file: name: /opt/refdata/PROD02/roman.delete state: touch 

I generated public / private keys and added public one to authorized_keys2 for the user I am running as on the target host.

When I try to start it, I get the following error:

 failed: [experiment01] => {"failed": true, "parsed": false} Traceback (most recent call last): File "/home/acplus_uat01/.ansible/tmp/ansible-tmp-1441921944.69-3869708445827/file", line 1999, in <module> main() File "/home/acplus_uat01/.ansible/tmp/ansible-tmp-1441921944.69-3869708445827/file", line 372, in main open(path, 'w').close() IOError: [Errno 2] No such file or directory: '/opt/refdata/PROD02/roman.delete' 

So, to check if I have problems with ssh or python, I tried this - I created a python file with one line:

 open('/opt/refdata/PROD02/roman.delete', 'w').close() 

and launched this from the same place and the same user as me, executed:

 cat test2.py | ssh -i ~/.ssh/myPrivateKey -q target_user@targethost python - 

and he created the file.

So my question is: where is the problem, why can't it create the file?

how i run the playbook is:

 ansible-playbook -i inventory/prod/ acc.yml -v --vault-password-file=~/.ansible-vault-pw --private-key ~/.ssh/myPrivateKey 

I also tried creating a file in / tmp / and ansible worked.

Edit: So, another update - I created a directory in which I am writing a file to a writeable world (777), and created the file. So the question is, what is different in Ansible, what

  cat test2.py | ssh -i ~/.ssh/myPrivateKey -q target_user@targethost python - 

works and does essentially the same thing through Ansible.

+6
source share
1 answer

If /opt/refdata/PROD02/ does not exist, you must first create a directory

 file: name: /opt/refdata/PROD02 state: directory recurse: yes mode: 0755 

Unrelated documentation says:

recurse . Set the specified file attributes ( applicable only to state = directory )

So Ansible cannot create a file and all directories in it with one command.

Then with the second command you should create a file.

 name: create fake file file: name: /opt/refdata/PROD02/roman.delete state: touch 
+3
source

All Articles