Don't run playbooks if role count == 0

There is no reason to try to run playbooks limited
to a role name when the role count is zero. It
actually fails because no hosts match.

Add a check to skip roles with count == 0.

Closes-Bug: #1955432
Change-Id: I5312e5362bdeac8337d1d0991e5a94ded5e83f3f
This commit is contained in:
Harald Jensås 2021-12-20 23:28:25 +01:00
parent 7e1d133308
commit b9b9dbd74e
2 changed files with 5 additions and 0 deletions

View File

@ -406,6 +406,8 @@ class TestRunRolePlaybooks(TestCase):
@mock.patch('tripleoclient.utils.run_ansible_playbook')
def test_role_playbooks(self, mock_run):
roles = [
# No playbooks should execute for the role if count is 0.
{'count': 0, 'name': 'ZeroNodesRole'},
{'count': 10, 'name': 'Compute'},
{
'count': 3,

View File

@ -3002,6 +3002,9 @@ def run_role_playbooks(self, working_dir, roles_file_dir, roles,
# Pre-Network Config
for role in roles:
if role.get('count', 1) == 0:
continue
role_playbooks = []
for x in role.get('ansible_playbooks', []):