The Ansible documentation has a list of Variable precedence
Some of them are clear to me but I wonder whether anybody coulde kinkdy shed some light on those 2.
20. role (and include_role) params
21. include params
usage, location, syntax.
I am trying to get Variable declaration a little further to the surface inside a little more complex playbook utilizing 2 roles I am currently working on.
concrete ... some values inside task files of a role should rather be declared as variables in a single location.
In a nutshell examples:
(full playbook)
- name: I'm a dummy play
hosts: localhost
roles:
- role: somerole
vars:
param1: "I'm a role param"
(task only)
- name: Including role somerole
ansible.builtin.include_role:
name: somerole
vars:
param1: "I'm an include role param"
(task only)
- name: Including a task file
ansible.builtin.include_tasks: sometasks.yaml
vars:
param1: "I'm an include param"
As a fictive and (most probably bad practice) example: if you include a role passing a parameter and later include a task file in that role passing that same parameter with a different value, the include param will take precedence over the role param.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With