The roles in this long-existing repository often use a concept like…
- name: COPY | copy 20auto-upgrades
ansible.builtin.copy:
src: "{{ _item }}"
dest: /etc/apt/apt.conf.d/20auto-upgrades
backup: no
owner: root
group: root
mode: "0644"
vars:
_files:
- "{{ autoupdate_20auto_upgrades | default([]) }}"
- "{{ topdir }}/files/autoupdate/{{ inventory_hostname_short }}/20auto-upgrades"
- "{{ topdir }}/files/autoupdate/{{ ansible_hostname }}/20auto-upgrades"
- "{{ topdir }}/files/autoupdate/{{ host_group | default(False) }}/20auto-upgrades"
- "20auto-upgrades.{{ ansible_distribution_release }}"
_item: "{{ lookup('ansible.builtin.first_found', _files) }}"
when:
- ansible_distribution == 'Debian'
- ansible_distribution_major_version is version_compare('9', '>=')
- _item is ansible.builtin.truthy
tags: autoupdate
to express the idea of having a configuration file default to roles/ROLENAME/files/FILENAME but overridable by host group, host, or configuration variable.
(They actually use lookup('ansible.builtin.first_found', _files, skip=True, errors='ignore'), but I removed the kwargs for debugging this.)
I was just adding a .trixie file and wanted to test this, and colour my surprise at the task just being skipped. Adding -vvvvv I saw that:
TASK [autoupdate : COPY | copy 20auto-upgrades] *****************************************************************
task path: /BASEDIR/roles/autoupdate/tasks/main.yml:154
looking for "20auto-upgrades.trixie" at "/BASEDIR/roles/autoupdate/None/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/roles/autoupdate/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/roles/autoupdate/tasks/None/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/roles/autoupdate/tasks/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/playbooks/hosts/None/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/playbooks/hosts/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/playbooks/hosts/None/20auto-upgrades.trixie"
looking for "20auto-upgrades.trixie" at "/BASEDIR/playbooks/hosts/20auto-upgrades.trixie"
[ERROR]: Task failed: The lookup plugin 'ansible.builtin.first_found' failed: No file was found when using first_found.
However, to my reading, this code is equivalent enough to the examples on ansible.builtin.first_found lookup – return first file found from list — Ansible Community Documentation which also refers to Search paths in Ansible — Ansible Community Documentation which indicates that it should indeed search roles/NAME/files/NAME.
But, apparently, something more than that is wrong. Not only failed it to find…
-rw-r--r-- 1 1015 1016 118 Nov 25 23:33 roles/autoupdate/files/20auto-upgrades.trixie
… but the other names and paths aren’t searched either.
What am I missing from the documentation that explains why this does not look up as intended?