Including this role makes it impossible to use --tags to select certain tasks/roles
So this is a strange one.
I have a playbook for managing a server. The playbook includes baseline host setup (ntp, sshd config, etc), backup setup (via this role), and finally workload setup that manages the services running on the host.
When I want to target a specific set of roles/tasks using the --tags option, I receive the following error from this role. Notably this only happens when I've specified a tag that doesn't include the borgbackup role.
$ ansible-playbook services.yml --tags workload-setup
... snip...
TASK [m3nu.ansible_role_borgbackup : Run OS-specific tasks] ****************************************************
Tuesday 24 August 2021 21:54:14 +0200 (0:00:21.284) 0:00:21.284 ********
fatal: [redactedhostname]: FAILED! =>
msg: No file was found when using first_found. Use errors='ignore' to allow this task to be skipped if no files are found
Here is a simple playbook to repro this:
---
- name: backup config
hosts: example
become: true
tags: [backup]
roles:
- role: m3nu.ansible_role_borgbackup
- name: workload
hosts: example
become: true
tags: [workload]
tasks:
- debug:
msg: setup app services
Running this with ansible-playbook test.yml will work fine, but running it with ansible-playbook test.yml --tags workload results in the error above.
The role loads system-specific variables from the "var" directory; those variables are contained in files named after the os family/distribution as they are reported by the fact gathering module:
# tasks/01_install.yml
- name: Include OS-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- "{{ ansible_lsb.id }}.yml"
Since you specify a tag at the playbook level (e.g "workload"), when you execute the playbook with -t workload the "gather_facts" step is not executed, therefore the role doesn't find a file to load. See https://github.com/ansible/ansible/issues/57529.
This needs the tag always, right?