1

I've got a python script that uses the ansible package to ping some remote servers. When executed manually (python devmanager.py) it works ok, but when the script is managed with supervisor it raises the following error:

Could not make dir /$HOME/.ansible/cp: [Errno 13] Permission denied: '/$HOME

The ansible command is quite simple:

    runner = ansible.runner.Runner(
            module_name='ping',
            module_args='',
            forks=10,
            inventory=inventory
    )

Same user in source and target systems. I've check permissions for the $HOME folder and didn't find anything weird.

Any idea what's is going on? Doesn't it know to translate the $HOME variable?

blong
  • 2,815
  • 8
  • 44
  • 110
klautern
  • 129
  • 3
  • 7
  • 26
  • Are you using `$HOME` in Python? It should be `os.environ['HOME']` – cdarke Aug 12 '15 at 10:00
  • No, that $HOME variable is something ansible uses to create a temporary folder to execute the command. It doesn't belong to my script – klautern Aug 12 '15 at 10:04
  • 1
    Also see this question, same problem: http://stackoverflow.com/questions/31842826/ansible-cannot-make-dir-home-ansible-cp – udondan Aug 12 '15 at 12:40

2 Answers2

1

You may give a try by altering the parameter "remote_tmp" in ansible.cfg.

Default:-$HOME/.ansible/tmp

Update:-/tmp/.ansible/tmp

On this case who ever the user try to run the playbook will have enough permission to create necessary temporary files in /tmp directory.

SPM
  • 714
  • 1
  • 8
  • 17
  • That sounds like a good idea. I tried but it says __init__() got an unexpected keyword argument 'remote_tmp'. This is how I tried it: runner = ansible.runner.Runner( module_name='ping', module_args='', forks=10, remote_tmp='/tmp/.ansible/tmp', inventory=inventory ) How should I define it? – klautern Aug 13 '15 at 06:19
  • Also tried updating **/etc/ansible/ansible.cfg** but it still uses the default path. I'm using the pyhon api anyway – klautern Aug 13 '15 at 06:48
  • Tried all these options to configure cfg, but still gets the default path. ANy idea why? 1st: ANSIBLE_CONFIG (an environment variable), 2nd: ansible.cfg (in the current directory), 3rd: .ansible.cfg (in the home directory), 4th: * /etc/ansible/ansible.cfg [link](http://docs.ansible.com/ansible/intro_configuration.html) – klautern Aug 13 '15 at 11:51
0

Yes, it seems that it doesn't escape the $HOME variable and tries to write under /$HOME.

plaes
  • 31,788
  • 11
  • 91
  • 89