Run ansible from foreman UI with delegate_to

I tried to run the following small ansible playbook via the foreman UI / REX Job:

- name: main playbook
  hosts: all
    - theforeman.foreman.setting:
        server_url: https://theforeman.example
        username: MyUser
        password: MyPW
        name: login_text
        value: MyLoginTitle
      delegate_to: localhost

It fails with:
fatal: [theforeman.example -> localhost]: FAILED! => {"changed": false, "msg": "Failed to connect to Foreman server: OSError: [Errno 13] Permission denied: '/usr/share/foreman-proxy/.cache'"}

The issue happens because of “delegate_to”. Using theforeman.foreman.setting is just an example.

A possible solution would be, to create a link from /usr/share/foreman-proxy/.cache to /var/tmp and set “foreman-proxy” / chmod 750 as permission rights.

What are your thoughts?

It’s not an issue of the delegate_to, but the fact that the Ansible module (theforeman.foreman.setting) wants to write to ~/.cache/ (for the apidoc cache) on whatever host it’s running against and can’t.

Yes, you can create that link. Or set XDG_CACHE_HOME.

well, without the delegate_to, the failure doesn’t occur. Can you imagine why?

- name: main playbook
  hosts: all
    - theforeman.foreman.setting:
        username: admin
        password: changeme
        name: login_text
        value: stupid
        XDG_CACHE_HOME: /tmp/.cache


Because it then uses SSH and gets a different $HOME? Maybe even on a different machine? My crystal ball is used up for today :wink:

It will also not occur if you replace theforeman.foreman.setting with a module that is not from theforeman.foreman and thus doesn’t try to write to ~/.cache/apypie/, like, uh, the copy module.

:slight_smile: :slight_smile: