Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible cannot make dir /$HOME/.ansible/cp

I'm getting a very strange error when I run ansible:

GATHERING FACTS *************************************************************** 
fatal: [i-0f55b6a4] => Could not make dir /$HOME/.ansible/cp: [Errno 13] Permission denied: '/$HOME'

TASK: [Task #1] *************************************************************** 
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/ubuntu/install.retry

i-0f55b6a4                 : ok=0    changed=0    unreachable=1    failed=0   

Normally, this playbook runs without problems, but I've recently made some changes so that the program that calls ansible is called from start-stop-daemon so that I will run as a service. The ultimate goal being to have a service that can run the playbook automatically, when it deems it necessary.

The beginning of the playbook looks like this:

---
- hosts: w_vm:main
  sudo: True
  tasks:
  - name: Task #1
    ...

sudo is set to True so I'm somewhat certain that the error is not on the target machine.

The generated invocation of ansible-playbook looks like this:

ansible-playbook -i /tmp/ansible3397486563152037600.inventory \
                    /home/ubuntu/playbooks/main_playbook.yml \
                    -e @/home/ubuntu/extra_params.json

I'm not sure if that Could not make dir /$HOME/.ansible/cp error is occurring on the server or on the remote machine, or why ansible is trying to make a directory named $HOME in /. This only happens when the program that calls ansible is called from the linux service, not when it's called explicitly from the command line.


I've asked a more specific question here: https://unix.stackexchange.com/questions/220841/start-stop-daemon-services-environment-variables-and-ansible

like image 350
FrustratedWithFormsDesigner Avatar asked Jan 07 '23 20:01

FrustratedWithFormsDesigner


2 Answers

Try sudo chown -R YOUR_USERNAME /home/YOUR_USERNAME/.ansible

like image 68
Justas Avatar answered Jan 17 '23 15:01

Justas


Late to answer but might be useful to someone. Check the ownership of ~/.ansible. The ownership of .ansible in the local machine (which runs ansible/ansible controller node) might be causing the problem. Do "chown -R username:groupname .ansible" (username:groupname should be of the user running the playbook) and try to run the playbook again

As an alternative remove this .ansible directory from controller node and rerun the playbook.

like image 23
Antony Avatar answered Jan 17 '23 16:01

Antony