ansible.builtin.unarchive - permission denied

291 Views Asked by At

I'm downloading a file to the ansible controller, distribute it to several (3) hosts und unarchive it to a certain directory. I have sudo access to all machines.

The code is the following:

- name: Install ZULU Java package
  hosts: jenkins
  become: true
  become_user: disasterman

  gather_facts: false

  tasks:

    - name: Download ZULU Java JDK
      delegate_to: localhost
      ansible.builtin.get_url:
        url: "{{ zulu_url }}"
        dest: /tmp/
      register: downloaded_file

    - name: Print output of registered var
      ansible.builtin.debug:
        var: downloaded_file.dest

    - name: Deliver and extract the package
      ansible.builtin.unarchive:
        src: "{{ downloaded_file.dest }}"
        dest: /opt/java/
        remote_src: false
        owner: buildmaster
        group: buildmaster
        mode: '775'

Despite becoming sudo, the module complains about "checkdir error: cannot create /opt/java/zulu17.42.19-ca-jdk17.0.7-linux_x64 Permission denied unable to process zulu17.42.19-ca-jdk17.0.7-linux_x64/."

The URI is provided on the commandline via -e. Download works and file is present.

I expected the archive to be extracted to the destination directory and set correct ownership flags.

Additional information due to comment #1

I added the user on top of the play which is usually defined in my inventory (host_vars, group_vars).

This is the host group:

ansible jenkins --list-hosts
  hosts (3):
    kcs-buildsrv
    kcs-build-fnode
    kcs-build-snode

With my user ('disasterman') I'm having sudo rights on all machines:

ansible jenkins -m ansible.builtin.command -a "whoami"
kcs-build-fnode | CHANGED | rc=0 >>
disasterman
kcs-build-snode | CHANGED | rc=0 >>
disasterman
kcs-buildsrv | CHANGED | rc=0 >>
disasterman

ansible jenkins -m ansible.builtin.command -a "whoami" -b
kcs-buildsrv | CHANGED | rc=0 >>
root
kcs-build-snode | CHANGED | rc=0 >>
root
kcs-build-fnode | CHANGED | rc=0 >>
root

If I unpack to /tmp/ instead of /opt/java/ I get the following error message:

Cannot change ownership of zulu17.42.19-ca-jdk17.0.7-linux_x64/ to buildmaster, as user disasterman

But of course I'm able to do it manually on the host:

disasterman@kcs-buildsrv:/tmp$ ll
drwxr-xr-x 10 disasterman disasterman    4096 Apr 10 15:07 zulu17.42.19-ca-jdk17.0.7-linux_x64/

disasterman@kcs-buildsrv:/tmp$ sudo chown -R buildmaster: zulu17.42.19-ca-jdk17.0.7-linux_x64/

disasterman@kcs-buildsrv:/tmp$ ll
drwxr-xr-x 10 buildmaster buildmaster    4096 Apr 10 15:07 zulu17.42.19-ca-jdk17.0.7-linux_x64/
0

There are 0 best solutions below