Search code examples
ansibleansible-inventory

Q: ansible; dynamic remote_tmp with inventory_hostname possible in ansible.cfg?


Situation:

  • 3 servers with the same shared NFS folder as home folder; (No I only have to use it; No I didn't set it up that way)
  • 3 different users
  • ansible is used to do task on each server
  • ansible 2.9.6
  • controler: ubuntu 18.04; Python 3.6.9;
  • server: Linux on xen; Python 2.6.9

Problem:

  • default remote_tmp path in ansible.cfg not working, cause of different users, hence the default remote path ~/.ansible/tmp with mask 700 is only write for the first ansible run, but the second and third run, renders errors, cause it is not writeable
  • custom remote_tmp with $RANDOM path (remote_tmp=/tmp/.ansible.$RANDOM) in ansible.cfg not working, cause $RANDOM changes during runtime and ansible cannot find files
  • setting the remote_tmp path in a inventory is not possible, at least I couldn't find a documentation
  • setting the remote_tmp path in a playbook is already to late.

Question:
Is there a possibility to have a customizable remote_tmp path in ansible.cfg, which is individual for each server, but stays constant during runtime? I want to avoid three seperate ansible.cfg files.


Solution

  • Well, after a good night sleep, I tired ansible_remote_tmp in the inventory and it seems to work.

    inventory:

    ...
        t00:
          hosts:
            t00vm1:
                ansible_ssh_common_args: '-F config/ssh.cfg'
                ansible_python_interpreter: python2
                ansible_remote_tmp: /tmp/.ansible.t00vm1
    ...
    

    Output:

    ...
    TASK [debug] ***********************************************************************************************************
    ok: [t00vm1] => {
        "msg": "/tmp/.mqc-ansible.t00vm1"
    }
    ...
    

    Hope that helps others, too.