I have the following playbook and role:
# File: ~/Development/ansible/collections/ansible_collections/my/collection/playbooks/webserver.yml
---
- name: Setup a Webserver
hosts:
- localhost
gather_facts: true
tasks:
- name: Certbot role
ansible.builtin.include_role:
name: my.collection.certbot
# File: ~/Development/ansible/collections/ansible_collections/my/collection/roles/certbot/tasks/main.yml
---
- name: Fetch OS dependent variables
ansible.builtin.include_vars: '{{ item }}'
with_first_found:
- files:
- '{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_release | default() }}.yml'
- '{{ ansible_facts.distribution }}.yml'
- '{{ ansible_facts.os_family }}_{{ ansible_facts.distribution_release | default() }}.yml'
- '{{ ansible_facts.os_family }}.yml'
skip: true
- name: Install Certbot
ansible.builtin.include_role:
name: geerlingguy.certbot
public: true
# File: ~/Development/ansible/collections/ansible_collections/my/collection/roles/certbot/vars/Debian.yml
---
certbot_cron_package: cron
certbot_python_packages:
- python3-openssl
# File: ~/Development/ansible/collections/ansible_collections/my/collection/roles/certbot/vars/main.yml
---
certbot_pip_dependencies:
- pyOpenSSL
certbot_hsts: true
certbot_create_if_missing: true
certbot_create_method: webroot
certbot_webroot: /var/www/letsencrypt
certbot_auto_renew: true
certbot_auto_renew_user: root
certbot_admin_email: ""
certbot_create_extra_args: ""
After executing ~/Development/ansible$ ANSIBLE_COLLECTIONS_PATH=${PWD}/collections ansible-playbook -i ./collections/ansible_collections/my/collection/inventory-dev ./collections/ansible_collections/my/collection/playbooks/webserver.yml
I get this:
fatal: [xrde-test]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'certbot_package' is undefined. 'certbot_package' is undefinednnThe error appears to be in '/Users/me/.ansible/roles/geerlingguy.certbot/tasks/install-with-package.yml': line 2, column 3, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nn---n- name: Install Certbot.n ^ heren"
}
The problem is that the included role geerlingguy.certbot
tries to import the role variables from the parent role folder my.collection.certbot
instead of from the included role folder. This seems weird to me.
When I try to rename ~/Development/ansible/collections/ansible_collections/my/collection/roles/certbot/vars/Debian.yml
to e.g. ~/Development/ansible/collections/ansible_collections/my/collection/roles/certbot/vars/Debian_bookworm.yml
it works.
Ansible 2.16.6 + Python 3.11.7