ansible Failed to create temporary directory despite ansible_system_tmpdirs: "/var/tmp"

132 views Asked by At

Below is my ansible playbook and the specific task that fails:

- name: My Playbook
  hosts: AppServer
  gather_facts: true
  become: yes
  vars:

    ansible_remote_tmp: "~/.ansible/tmp"
    ansible_system_tmpdirs: "/var/tmp"  
    tomcat_home: "{{ hostvars[inventory_hostname]['tomcat_home_input'] }}"

  tasks:
    ...
    ...
      - name: Ensure the target directory is deleted (if it exists)
        ansible.builtin.file:
          path: "{{ tomcat_home_item | trim }}/aredeploy"
          state: absent
        register: directory_deleted
        ignore_errors: yes
        become: true
        become_user: "{{ become_user_global }}"

Output:

TASK [Printing final path] *****************************************************
ok: [remhost77] => {
    "msg": "/root/mydir/package-571-DEV.zip"
}

TASK [Execute script to download zip artifacts from JFROG] *********************
changed: [remhost77 -> localhost]

TASK [Ensure the target directory is deleted (if it exists)] *******************
fatal: [remhost77]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \\"/tmp\\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \\"` echo /var/tmp `\\"&& mkdir \\"` echo /var/tmp/ansible-tmp-1708940107.5384886-122-272466693207348 `\\" && echo ansible-tmp-1708940107.5384886-122-272466693207348=\\"` echo /var/tmp/ansible-tmp-1708940107.5384886-122-272466693207348 `\\" ), exited with result 2", "unreachable": true}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
remhost77               : ok=18   changed=4    unreachable=1    failed=0    skipped=2    rescued=0    ignored=0   

If i change from /var/tmp/ to just tmp i get the below error:

{
  "msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 2, err: chmod: ERROR: Different file system ACL types cannot be merged: /tmp/ansible-tmp-1708941960.8785305-121-146387316011020/\nchmod: ERROR: Different file system ACL types cannot be merged: /tmp/ansible-tmp-1708941960.8785305-121-146387316011020/AnsiballZ_file.py\n}). For information on working around this, see https://docs.ansible.com/ansible-core/2.12/user_guide/become.html#risks-of-becoming-an-unprivileged-user",
  "_ansible_no_log": false
}

Note:

  • There are several tasks by olamuser (ansibleuser) on the target that works fine before it errors on the above task. The conclusion i can make is that there is no issue with the account we are using to execute the tasks as it partially performs many tasks.

  • I do not have option to change any ansible config file as this ansible trigger is using OLAM docker process managed by a different team. I can just make changes to the playbook code.

Below are the details of the /var/tmp directory.

wladmin@remhost77$ ls -ld /var/tmp
drwxr-xr-x   3 root     root          15 Feb 26 03:37 /var/tmp

and

wladmin@remhost77$ ls -ltr /var/tmp
total 83
-rw-------   1 root     root        4351 Mar 11  2022 log4j_findings_unix_dir.sh
-rw-------   1 root     root        5090 Mar 11  2022 log4j_findings_unix.sh
drwx------   3 root     root           3 Feb 23 10:07 BES
-rw-------   1 root     root           0 Feb 25 02:51 PowerMT
-rw-------   1 root     root          20 Feb 25 02:53 centrify_issue.flg

I reffered to the below links before posting:

Ansible error "failed to create temporary directory"

remote tmp directory not set for ansible script execution

Can you please suggest?

0

There are 0 answers