New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible role dependencies are not passing variables as expected #68922
Comments
Files identified in the description: If these files are incorrect, please update the |
The problem here is a misunderstanding about how role variables are scoped as well as how roles are processed. Role variables are scoped at the play level, and roles are all parsed and merged into the play at playbook parsing time. As a result, the last defined variable from This can be disabled through the config with https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-private-role-vars Otherwise, you can switch from role
Role params are scoped to the role, and not the play. I won't close this, as the documentation is incorrect, and needs to be updated accordingly. |
another question does the role dependencies behavior is the same as import_role or include_role, or it's own logic? @sivel |
Thanks so much for the quick reply - this is really useful to know and glad that the documentation can be updated as a result of this. One query however - I just tested with ANSIBLE_PRIVATE_ROLE_VARS set to true, and the output now returns:
Surely this is not as intended either? I did test with parameters and this works as you suggested, so just curious about the above parameter setting. |
@liuyangc3 the |
The other option is switching to use - include_role:
name: wheel
vars:
n: 1
- include_role:
name: wheel
vars:
n: 2
- include_role:
name: wheel
vars:
n: 3
- include_role:
name: wheel
vars:
n: 4 |
Awesome - thanks @sivel - your answers have really helped me. Looking forward to seeing the updated documentation page - if you want me to review or help with anything please do let me know. |
possibly fixed by #69040 |
This was helpful. I setup a role to get secrets from HashiCorp vault. In some situations it was being inserted via include_role and other times via a role dependency. Sometimes I was getting the behavior I expected and sometime my variables were just set to the value of the last call. Using the role param syntax vs role vars has cleaned up the issue. |
SUMMARY
Ansible role dependencies are not passing variables as expected
ISSUE TYPE
Bug ReportCOMPONENT NAME
Role dependencies
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
CentOS 7.7.1908 64 bit running on libvirt
STEPS TO REPRODUCE
Create the car, wheel, tire and brake roles as described here: https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html
Run a playbook calling the roles
EXPECTED RESULTS
The documentation states:
The resulting order of execution would be as follows:
tire(n=1)
brake(n=1)
wheel(n=1)
tire(n=2)
brake(n=2)
wheel(n=2)
...
car
ACTUAL RESULTS
I am seeing:
tire(n=4)
brake(n=4)
wheel(n=4)
tire(n=4)
brake(n=4)
wheel(n=4)
...
car
The text was updated successfully, but these errors were encountered: