Running role dependencies multiple times in one play
Ansible treats duplicate role dependencies like duplicate roles listed underroles:: Ansible only executes role dependencies once, even if defined multiple times, unless the parameters, tags, or when clause defined on the role are different for each definition. If two roles in a play both list a third role as a dependency, Ansible only runs that role dependency once, unless you pass different parameters, tags, when clause, or useallow_duplicates:truein the role you want to run multiple times. SeeGalaxy role dependenciesfor more details.
For example, a role namedcardepends on a role namedwheelas follows:
And thewheelrole depends on two roles:tireandbrake. Themeta/main.ymlfor wheel would then contain the following:
And themeta/main.ymlfortireandbrakewould contain the following:
The resulting order of execution would be as follows:
To useallow_duplicates:truewith role dependencies, you must specify it for the role listed underdependencies, not for the role that lists it. In the example above,allow_duplicates:trueappears in themeta/main.ymlof thetireandbrakeroles. Thewheelrole does not requireallow_duplicates:true, because each instance defined bycaruses different parameter values.