Ansible shows error on wrong place

dietrich
Sun, 01 Mar 2026 07:03:34 +0000
Get Help

Hi,
I´m just starting with ansible and finishing my first playbook. It´s about downloading released packages from private Github Repositories. They can be either whl packages or packed tar.gz. Therefore I implemented different tasks for each case. The results seem to be ok, the file is downloaded and extracted properly. But there is a very confusing error message appearing when downloading a .whl file, if downloading a tar.gz file, there is no error message.

Here´s the code:

    - name: Extract tar.gz file
      ansible.builtin.unarchive:
        src: "{{ dowloaded_file.dest }}"
        dest: "{{ package_dir }}"
      register: file_to_copy
      when: dowloaded_file.dest.endswith('.tar.gz')

    - name: Set file_to_copy if whl package
      ansible.builtin.set_fact:
        file_to_copy: "{{ dowloaded_file.dest }}"
      when: dowloaded_file.dest.endswith('.whl')

    - name: Print filename 2
      ansible.builtin.debug:
        msg: "After unpacking: {{ file_to_copy }}"

    - name: Copy whl file
      ansible.builtin.copy:
        src: "{{ file_to_copy }}"
        dest: "{{ package_dir }}"
        mode: "0755"
      #register: files

    # there are multiple branches needed, depending on the file type
    - name: Print filename
      ansible.builtin.debug:
        msg: "Finished: {{ file_to_copy }}"

The error message is this:

TASK [Copy whl file] ***************************************************************************************
[ERROR]: Task failed: '_AnsibleTaggedDict' object has no attribute 'endswith'
Origin: /home/dw/code/openocd-tcl-controller/repo_config/ansible/download_release.yml:80:7

78         msg: "After unpacking: {{ file_to_copy }}"
79
80     - name: Copy whl file
         ^ column 7

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Task failed: '_AnsibleTaggedDict' object has no attribute 'endswith'"}

PLAY RECAP *************************************************************************************************
localhost                  : ok=11   changed=0    unreachable=0

Whats confusing is: the Task “Copy whl file” does not have any endswith functionality used from my point of view.
Can someone explain what is going on there? Even if it´s working out, I don´t like to have this error there and want to fix it.

BR
Dietrich

11 posts - 5 participants