diff --git a/changelogs/fragments/object_diff.yml b/changelogs/fragments/object_diff.yml new file mode 100644 index 00000000..97c0c44c --- /dev/null +++ b/changelogs/fragments/object_diff.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - fix global execution environments comparison and exportation. Update the filetree_create role acordingly. +... diff --git a/plugins/lookup/controller_object_diff.py b/plugins/lookup/controller_object_diff.py index 0afe2d4b..6cfd600e 100644 --- a/plugins/lookup/controller_object_diff.py +++ b/plugins/lookup/controller_object_diff.py @@ -221,6 +221,13 @@ def run(self, terms, variables=None, **kwargs): item.update({"unified_job_template": item["summary_fields"]["unified_job_template"]["name"]}) item.update({"workflow_job_template": item["summary_fields"]["workflow_job_template"]["name"]}) item.pop("summary_fields") + elif api_list[0]["type"] == "execution_environment": + for item in api_list_reduced: + if 'organization' in item['summary_fields']: + item.update({"organization": item['summary_fields']['organization']['name']}) + else: + item.update({"organization": None}) + item.pop("summary_fields") elif api_list[0]["type"] == "schedule": for item in api_list_reduced: item.update({"unified_job_template": item["summary_fields"]["unified_job_template"]["name"]}) diff --git a/roles/filetree_create/templates/controller_execution_environments.j2 b/roles/filetree_create/templates/controller_execution_environments.j2 index 9d9d7ea5..b840a329 100644 --- a/roles/filetree_create/templates/controller_execution_environments.j2 +++ b/roles/filetree_create/templates/controller_execution_environments.j2 @@ -1,27 +1,29 @@ --- controller_execution_environments: {{ [] if current_execution_environments_asset_value | length == 0 }} {% for ee in current_execution_environments_asset_value %} -{% if organization_filter is not defined or (ee.summary_fields.organization is defined and ee.summary_fields.organization.name is match(organization_filter)) %} +{% if organization_filter is not defined or (ee.summary_fields.organization is defined and ee.summary_fields.organization.name is match(organization_filter)) %} - name: "{{ ee.name }}" description: !unsafe '{{ template_overrides_resources.ee[ee.name].description | default(template_overrides_global.ee.description) | default(ee.description) | regex_replace("'", "''") }}' -{% if ee.summary_fields.organization.name is defined %} +{% if ee.summary_fields.organization.name is defined %} organization: "{{ ee.summary_fields.organization.name }}" -{% endif %} +{% else %} + organization: # Leave this empty organization to let the object_diff role to work properly +{% endif %} image: "{{ template_overrides_resources.ee[ee.name].image | default(template_overrides_global.ee.image) | default(ee.image) }}" pull: "{{ template_overrides_resources.ee[ee.name].pull | default(template_overrides_global.ee.pull) | default(ee.pull) }}" -{% if template_overrides_resources.ee[ee.name].credential is defined +{% if template_overrides_resources.ee[ee.name].credential is defined or template_overrides_global.ee.credential is defined or ee.summary_fields.credential is defined %} credential: "{{ template_overrides_resources.ee[ee.name].credential | default(template_overrides_global.ee.credential) | default(ee.summary_fields.credential.name) }}" -{% endif %} -{% endif %} +{% endif %} +{% endif %} {% endfor %} ... diff --git a/roles/object_diff/tasks/controller_execution_environments.yml b/roles/object_diff/tasks/controller_execution_environments.yml index 449c223d..3170deaf 100644 --- a/roles/object_diff/tasks/controller_execution_environments.yml +++ b/roles/object_diff/tasks/controller_execution_environments.yml @@ -1,5 +1,5 @@ --- -- name: "Block to be executed only when connected against an AAP instance (not Tower)" +- name: "Block to be executed only when connected against an AAP instance" block: - name: Get the organization ID ansible.builtin.set_fact: @@ -7,11 +7,14 @@ query_params={'name': orgs}, host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs) }}" + when: + - orgs is defined + - orgs | length > 0 - name: "Get the API list of all Execution Environments in Organization {{ orgs }}" ansible.builtin.set_fact: __controller_api_execution_environments: "{{ query('ansible.platform.gateway_api', 'api/controller/' + controller_api_version + '/execution_environments', - query_params={'organization': __controller_organization_id.id}, + query_params={'organization': __controller_organization_id.id} if __controller_organization_id is defined else {}, host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs, return_all=true, max_objects=query_controller_api_max_objects) }}"