From 41014e62b7d6c3d59f692a3ff18bf7b2a7e83ff3 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 27 Apr 2020 16:15:11 -0400 Subject: [PATCH] Avoid applying galaxy settings if no user settings exist (#4262) --- awx/main/tasks.py | 25 +++++++++++++++---------- awx/playbooks/project_update.yml | 8 ++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index dd27a7d849..e8a5bf5a57 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -2074,29 +2074,34 @@ class RunProjectUpdate(BaseTask): if settings.GALAXY_IGNORE_CERTS: env['ANSIBLE_GALAXY_IGNORE'] = True # Set up the public Galaxy server, if enabled + galaxy_configured = False if settings.PUBLIC_GALAXY_ENABLED: - galaxy_servers = [settings.PUBLIC_GALAXY_SERVER] + galaxy_servers = [settings.PUBLIC_GALAXY_SERVER] # static setting else: + galaxy_configured = True galaxy_servers = [] # Set up fallback Galaxy servers, if configured if settings.FALLBACK_GALAXY_SERVERS: + galaxy_configured = True galaxy_servers = settings.FALLBACK_GALAXY_SERVERS + galaxy_servers # Set up the primary Galaxy server, if configured if settings.PRIMARY_GALAXY_URL: + galaxy_configured = True galaxy_servers = [{'id': 'primary_galaxy'}] + galaxy_servers for key in GALAXY_SERVER_FIELDS: value = getattr(settings, 'PRIMARY_GALAXY_{}'.format(key.upper())) if value: galaxy_servers[0][key] = value - for server in galaxy_servers: - for key in GALAXY_SERVER_FIELDS: - if not server.get(key): - continue - env_key = ('ANSIBLE_GALAXY_SERVER_{}_{}'.format(server.get('id', 'unnamed'), key)).upper() - env[env_key] = server[key] - if galaxy_servers: - # now set the precedence of galaxy servers - env['ANSIBLE_GALAXY_SERVER_LIST'] = ','.join([server.get('id', 'unnamed') for server in galaxy_servers]) + if galaxy_configured: + for server in galaxy_servers: + for key in GALAXY_SERVER_FIELDS: + if not server.get(key): + continue + env_key = ('ANSIBLE_GALAXY_SERVER_{}_{}'.format(server.get('id', 'unnamed'), key)).upper() + env[env_key] = server[key] + if galaxy_servers: + # now set the precedence of galaxy servers + env['ANSIBLE_GALAXY_SERVER_LIST'] = ','.join([server.get('id', 'unnamed') for server in galaxy_servers]) return env def _build_scm_url_extra_vars(self, project_update): diff --git a/awx/playbooks/project_update.yml b/awx/playbooks/project_update.yml index 9c61c81093..fc791069a9 100644 --- a/awx/playbooks/project_update.yml +++ b/awx/playbooks/project_update.yml @@ -136,9 +136,9 @@ register: doesRequirementsExist - name: fetch galaxy roles from requirements.yml - command: ansible-galaxy install -r requirements.yml -p {{roles_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }} + command: ansible-galaxy install -r roles/requirements.yml -p {{roles_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }} args: - chdir: "{{project_path|quote}}/roles" + chdir: "{{project_path|quote}}" register: galaxy_result when: doesRequirementsExist.stat.exists changed_when: "'was installed successfully' in galaxy_result.stdout" @@ -157,9 +157,9 @@ register: doesCollectionRequirementsExist - name: fetch galaxy collections from collections/requirements.yml - command: ansible-galaxy collection install -r requirements.yml -p {{collections_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }} + command: ansible-galaxy collection install -r collections/requirements.yml -p {{collections_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }} args: - chdir: "{{project_path|quote}}/collections" + chdir: "{{project_path|quote}}" register: galaxy_collection_result when: doesCollectionRequirementsExist.stat.exists changed_when: "'Installing ' in galaxy_collection_result.stdout"