Merge pull request #11865 from AlanCoding/galaxy_task_env

Add user-defined environment variables to ansible-galaxy commands
This commit is contained in:
Alan Rominger
2022-04-01 15:24:54 -04:00
committed by GitHub
8 changed files with 90 additions and 18 deletions

View File

@@ -282,6 +282,19 @@ register(
placeholder={'HTTP_PROXY': 'myproxy.local:8080'}, placeholder={'HTTP_PROXY': 'myproxy.local:8080'},
) )
register(
'GALAXY_TASK_ENV',
field_class=fields.KeyValueField,
label=_('Environment Variables for Galaxy Commands'),
help_text=_(
'Additional environment variables set for invocations of ansible-galaxy within project updates. '
'Useful if you must use a proxy server for ansible-galaxy but not git.'
),
category=_('Jobs'),
category_slug='jobs',
placeholder={'HTTP_PROXY': 'myproxy.local:8080'},
)
register( register(
'INSIGHTS_TRACKING_STATE', 'INSIGHTS_TRACKING_STATE',
field_class=fields.BooleanField, field_class=fields.BooleanField,

View File

@@ -1161,6 +1161,7 @@ class RunProjectUpdate(BaseTask):
'scm_track_submodules': project_update.scm_track_submodules, 'scm_track_submodules': project_update.scm_track_submodules,
'roles_enabled': galaxy_creds_are_defined and settings.AWX_ROLES_ENABLED, 'roles_enabled': galaxy_creds_are_defined and settings.AWX_ROLES_ENABLED,
'collections_enabled': galaxy_creds_are_defined and settings.AWX_COLLECTIONS_ENABLED, 'collections_enabled': galaxy_creds_are_defined and settings.AWX_COLLECTIONS_ENABLED,
'galaxy_task_env': settings.GALAXY_TASK_ENV,
} }
) )
# apply custom refspec from user for PR refs and the like # apply custom refspec from user for PR refs and the like

View File

@@ -15,6 +15,7 @@
# scm_track_submodules: true/false # scm_track_submodules: true/false
# roles_enabled: Value of the global setting to enable roles downloading # roles_enabled: Value of the global setting to enable roles downloading
# collections_enabled: Value of the global setting to enable collections downloading # collections_enabled: Value of the global setting to enable collections downloading
# galaxy_task_env: environment variables to use specifically for ansible-galaxy commands
# awx_version: Current running version of the awx or tower as a string # awx_version: Current running version of the awx or tower as a string
# awx_license_type: "open" for AWX; else presume Tower # awx_license_type: "open" for AWX; else presume Tower
@@ -154,18 +155,26 @@
gather_facts: false gather_facts: false
connection: local connection: local
name: Install content with ansible-galaxy command if necessary name: Install content with ansible-galaxy command if necessary
vars:
galaxy_task_env: # configure in settings
additional_collections_env:
# These environment variables are used for installing collections, in addition to galaxy_task_env
# setting the collections paths silences warnings
ANSIBLE_COLLECTIONS_PATHS: "{{projects_root}}/.__awx_cache/{{local_path}}/stage/requirements_collections"
# Put the local tmp directory in same volume as collection destination
# otherwise, files cannot be moved accross volumes and will cause error
ANSIBLE_LOCAL_TEMP: "{{projects_root}}/.__awx_cache/{{local_path}}/stage/tmp"
tasks: tasks:
- name: Check content sync settings - name: Check content sync settings
debug: block:
msg: "Collection and role syncing disabled. Check the AWX_ROLES_ENABLED and AWX_COLLECTIONS_ENABLED settings and Galaxy credentials on the project's organization." - debug:
when: not roles_enabled|bool and not collections_enabled|bool msg: >
tags: Collection and role syncing disabled. Check the AWX_ROLES_ENABLED and
- install_roles AWX_COLLECTIONS_ENABLED settings and Galaxy credentials on the project's organization.
- install_collections
- meta: end_play
- name:
meta: end_play
when: not roles_enabled|bool and not collections_enabled|bool when: not roles_enabled|bool and not collections_enabled|bool
tags: tags:
- install_roles - install_roles
@@ -184,9 +193,7 @@
- "{{project_path|quote}}/roles/requirements.yaml" - "{{project_path|quote}}/roles/requirements.yaml"
- "{{project_path|quote}}/roles/requirements.yml" - "{{project_path|quote}}/roles/requirements.yml"
changed_when: "'was installed successfully' in galaxy_result.stdout" changed_when: "'was installed successfully' in galaxy_result.stdout"
environment: environment: "{{ galaxy_task_env }}"
ANSIBLE_FORCE_COLOR: false
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
when: roles_enabled|bool when: roles_enabled|bool
tags: tags:
@@ -207,13 +214,7 @@
- "{{project_path|quote}}/requirements.yaml" - "{{project_path|quote}}/requirements.yaml"
- "{{project_path|quote}}/requirements.yml" - "{{project_path|quote}}/requirements.yml"
changed_when: "'Installing ' in galaxy_collection_result.stdout" changed_when: "'Installing ' in galaxy_collection_result.stdout"
environment: environment: "{{ additional_collections_env | combine(galaxy_task_env) }}"
ANSIBLE_FORCE_COLOR: false
ANSIBLE_COLLECTIONS_PATHS: "{{projects_root}}/.__awx_cache/{{local_path}}/stage/requirements_collections"
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
# Put the local tmp directory in same volume as collection destination
# otherwise, files cannot be moved accross volumes and will cause error
ANSIBLE_LOCAL_TEMP: "{{projects_root}}/.__awx_cache/{{local_path}}/stage/tmp"
when: when:
- "ansible_version.full is version_compare('2.9', '>=')" - "ansible_version.full is version_compare('2.9', '>=')"

View File

@@ -561,6 +561,10 @@ ANSIBLE_INVENTORY_UNPARSED_FAILED = True
# Additional environment variables to be passed to the ansible subprocesses # Additional environment variables to be passed to the ansible subprocesses
AWX_TASK_ENV = {} AWX_TASK_ENV = {}
# Additional environment variables to apply when running ansible-galaxy commands
# to fetch Ansible content - roles and collections
GALAXY_TASK_ENV = {'ANSIBLE_FORCE_COLOR': 'false', 'GIT_SSH_COMMAND': "ssh -o StrictHostKeyChecking=no"}
# Rebuild Host Smart Inventory memberships. # Rebuild Host Smart Inventory memberships.
AWX_REBUILD_SMART_MEMBERSHIP = False AWX_REBUILD_SMART_MEMBERSHIP = False

View File

@@ -85,6 +85,7 @@ function JobsEdit() {
form.AWX_ANSIBLE_CALLBACK_PLUGINS form.AWX_ANSIBLE_CALLBACK_PLUGINS
), ),
AWX_TASK_ENV: formatJson(form.AWX_TASK_ENV), AWX_TASK_ENV: formatJson(form.AWX_TASK_ENV),
GALAXY_TASK_ENV: formatJson(form.GALAXY_TASK_ENV),
}); });
}; };
@@ -217,6 +218,10 @@ function JobsEdit() {
config={jobs.AWX_ISOLATION_SHOW_PATHS} config={jobs.AWX_ISOLATION_SHOW_PATHS}
/> />
<ObjectField name="AWX_TASK_ENV" config={jobs.AWX_TASK_ENV} /> <ObjectField name="AWX_TASK_ENV" config={jobs.AWX_TASK_ENV} />
<ObjectField
name="GALAXY_TASK_ENV"
config={jobs.GALAXY_TASK_ENV}
/>
{submitError && <FormSubmitError error={submitError} />} {submitError && <FormSubmitError error={submitError} />}
{revertError && <FormSubmitError error={revertError} />} {revertError && <FormSubmitError error={revertError} />}
</FormColumnLayout> </FormColumnLayout>

View File

@@ -231,6 +231,26 @@
"read_only": false "read_only": false
} }
}, },
"GALAXY_TASK_ENV": {
"type": "nested object",
"required": true,
"label": "Environment Variables for Galaxy Commands",
"help_text": "Additional environment variables set for invocations of ansible-galaxy within project updates. Useful if you must use a proxy server for ansible-galaxy but not git.",
"category": "Jobs",
"category_slug": "jobs",
"placeholder": {
"HTTP_PROXY": "myproxy.local:8080"
},
"default": {
"ANSIBLE_FORCE_COLOR": "false",
"GIT_SSH_COMMAND": "ssh -o StrictHostKeyChecking=no"
},
"child": {
"type": "string",
"required": true,
"read_only": false
}
},
"INSIGHTS_TRACKING_STATE": { "INSIGHTS_TRACKING_STATE": {
"type": "boolean", "type": "boolean",
"required": false, "required": false,
@@ -3942,6 +3962,26 @@
"type": "string" "type": "string"
} }
}, },
"GALAXY_TASK_ENV": {
"type": "nested object",
"required": true,
"label": "Environment Variables for Galaxy Commands",
"help_text": "Additional environment variables set for invocations of ansible-galaxy within project updates. Useful if you must use a proxy server for ansible-galaxy but not git.",
"category": "Jobs",
"category_slug": "jobs",
"placeholder": {
"HTTP_PROXY": "myproxy.local:8080"
},
"default": {
"ANSIBLE_FORCE_COLOR": "false",
"GIT_SSH_COMMAND": "ssh -o StrictHostKeyChecking=no"
},
"child": {
"type": "string",
"required": true,
"read_only": false
}
},
"INSIGHTS_TRACKING_STATE": { "INSIGHTS_TRACKING_STATE": {
"type": "boolean", "type": "boolean",
"label": "Gather data for Insights for Ansible Automation Platform", "label": "Gather data for Insights for Ansible Automation Platform",

View File

@@ -38,6 +38,10 @@
"AWX_ISOLATION_BASE_PATH":"/tmp", "AWX_ISOLATION_BASE_PATH":"/tmp",
"AWX_ISOLATION_SHOW_PATHS":[], "AWX_ISOLATION_SHOW_PATHS":[],
"AWX_TASK_ENV":{}, "AWX_TASK_ENV":{},
"GALAXY_TASK_ENV": {
"ANSIBLE_FORCE_COLOR": "false",
"GIT_SSH_COMMAND": "ssh -o StrictHostKeyChecking=no"
},
"INSIGHTS_TRACKING_STATE":false, "INSIGHTS_TRACKING_STATE":false,
"PROJECT_UPDATE_VVV":false, "PROJECT_UPDATE_VVV":false,
"AWX_ROLES_ENABLED":true, "AWX_ROLES_ENABLED":true,

View File

@@ -7,6 +7,10 @@
"AWX_ISOLATION_BASE_PATH": "/tmp", "AWX_ISOLATION_BASE_PATH": "/tmp",
"AWX_ISOLATION_SHOW_PATHS": [], "AWX_ISOLATION_SHOW_PATHS": [],
"AWX_TASK_ENV": {}, "AWX_TASK_ENV": {},
"GALAXY_TASK_ENV": {
"ANSIBLE_FORCE_COLOR": "false",
"GIT_SSH_COMMAND": "ssh -o StrictHostKeyChecking=no"
},
"PROJECT_UPDATE_VVV": false, "PROJECT_UPDATE_VVV": false,
"AWX_ROLES_ENABLED": true, "AWX_ROLES_ENABLED": true,
"AWX_COLLECTIONS_ENABLED": true, "AWX_COLLECTIONS_ENABLED": true,