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

FrustratedWithFormsDesigner picture FrustratedWithFormsDesigner · Aug 5, 2015 · Viewed 7k times · Source

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

Answer

Justas picture Justas · Nov 9, 2015

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