1

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/
adminkc
  • 11
  • 2
  • 1
    Since the three targets nodes are `hosts: jenkins` and `buildmaster:buildmaster` can you provide more information regarding them? Because of `sudo` is possbible do you have full acccess there? Are you able to copy and unarchive there manually? – U880D Jun 16 '23 at 12:06
  • Updated the original post due to better formatting options. – adminkc Jun 16 '23 at 16:43
  • Is the user in the inventory defined with `become_user` or `ansible_user`? – tyagdit Jun 17 '23 at 08:00
  • It's the same user on all machines. connection user == ansible user == become user. If I understand the documentation correctly, because the user (disasterman) ist the user which can do `sudo` on all machines. – adminkc Jun 22 '23 at 07:19

0 Answers0