From 4eec8284306082d54945cde935ef15912bb957c4 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 12 Jul 2017 17:33:26 -0700 Subject: [PATCH] Add child roles before parent This lets a child job add roles which take precedence over its parent. This should be safe to do now that playbooks only run with the roles they were defined with. Change-Id: I5c6c506f5a59562edc360771393d31c11ea42835 --- doc/source/user/config.rst | 8 ++++++-- zuul/model.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/source/user/config.rst b/doc/source/user/config.rst index 64dc393fec..24126f7186 100644 --- a/doc/source/user/config.rst +++ b/doc/source/user/config.rst @@ -698,7 +698,9 @@ unless otherwise specified: Ansible Galaxy, or a Zuul role, which is a role provided by a project managed by Zuul. Zuul roles are able to benefit from speculative merging and cross-project dependencies when used by - playbooks in untrusted projects. + playbooks in untrusted projects. Roles are added to the Ansible + role path in the order they appear on the job -- roles earlier in + the list will take precedence over those which follow. In the case of job inheritance or variance, the roles used for each of the playbooks run by the job will be only those which were @@ -709,7 +711,9 @@ unless otherwise specified: pre and post playbooks, then any roles added by the child will be available to the child's playbooks. This is so that a job which inherits from a parent does not inadvertantly alter the behavior of - the parent's playbooks by the addition of conflicting roles. + the parent's playbooks by the addition of conflicting roles. Roles + added by a child will appear before those it inherits from its + parent. A project which supplies a role may be structured in one of two configurations: a bare role (in which the role exists at the root of diff --git a/zuul/model.py b/zuul/model.py index 66c043d5f8..9bdef012a9 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -863,9 +863,9 @@ class Job(object): def addRoles(self, roles): newroles = list(self.roles) - for role in roles: + for role in reversed(roles): if role not in newroles: - newroles.append(role) + newroles.insert(0, role) self.roles = tuple(newroles) def updateVariables(self, other_vars):