diff --git a/changelogs/fragments/dependency_check_control.yml b/changelogs/fragments/dependency_check_control.yml new file mode 100644 index 000000000..68ac9e1f1 --- /dev/null +++ b/changelogs/fragments/dependency_check_control.yml @@ -0,0 +1,4 @@ +--- +minor_changes: + - Add ability to disable dependency check +... diff --git a/changelogs/fragments/filetree_create_loop_issue.yaml b/changelogs/fragments/filetree_create_loop_issue.yaml new file mode 100644 index 000000000..03f03f7ca --- /dev/null +++ b/changelogs/fragments/filetree_create_loop_issue.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fixed issue with loops that were getting always empty list of objects diff --git a/roles/filetree_create/tasks/applications.yml b/roles/filetree_create/tasks/applications.yml index 7dd8000a5..e53e58548 100644 --- a/roles/filetree_create/tasks/applications.yml +++ b/roles/filetree_create/tasks/applications.yml @@ -53,12 +53,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/applications" - loop: >- - {{ (applications_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) - + ([default(organization)] if ((applications_lookvar | map(attribute='summary_fields') - | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) - }} + loop: "{{ (applications_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((applications_lookvar | map(attribute='summary_fields') + | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/credentials.yml b/roles/filetree_create/tasks/credentials.yml index 9335ad1d0..5848c5fc7 100644 --- a/roles/filetree_create/tasks/credentials.yml +++ b/roles/filetree_create/tasks/credentials.yml @@ -53,12 +53,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path }}/credentials" - loop: >- - {{ (credentials_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) - + ([(organization if organization is defined else 'ORGANIZATIONLESS')] if ((credentials_lookvar | - map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) - }} + loop: "{{ (credentials_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((credentials_lookvar | + map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/job_templates.yml b/roles/filetree_create/tasks/job_templates.yml index 6a97563aa..3f4190ed2 100644 --- a/roles/filetree_create/tasks/job_templates.yml +++ b/roles/filetree_create/tasks/job_templates.yml @@ -87,12 +87,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/job_templates" - loop: >- - {{ (job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - [organization] if (job_templates_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten | length > 0) else [] - }} + loop: "{{ (job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((job_templates_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/labels.yml b/roles/filetree_create/tasks/labels.yml index 10025581c..2eef9ac56 100644 --- a/roles/filetree_create/tasks/labels.yml +++ b/roles/filetree_create/tasks/labels.yml @@ -54,7 +54,7 @@ vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/labels" loop: "{{ (labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | map(attribute='organization') | map(attribute='name') | list | flatten | unique) - + (['ORGANIZATIONLESS'] if ((labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + + ([organization] if ((labels_lookvar | map(attribute='summary_fields') | selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) }}" loop_control: loop_var: needed_path diff --git a/roles/filetree_create/tasks/notification_templates.yml b/roles/filetree_create/tasks/notification_templates.yml index f1122776e..4318c9e7d 100644 --- a/roles/filetree_create/tasks/notification_templates.yml +++ b/roles/filetree_create/tasks/notification_templates.yml @@ -50,12 +50,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/notification_templates" - loop: >- - {{ (notification_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - [organization] if (notification_templates_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten | length > 0) else [] - }} + loop: "{{ (notification_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((notification_templates_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/projects.yml b/roles/filetree_create/tasks/projects.yml index 1609d8f01..0c3358270 100644 --- a/roles/filetree_create/tasks/projects.yml +++ b/roles/filetree_create/tasks/projects.yml @@ -64,12 +64,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/projects" - loop: >- - {{ (projects_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - [organization] if (projects_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten | length > 0) else [] - }}" + loop: "{{ (projects_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((projects_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list) | flatten | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/teams.yml b/roles/filetree_create/tasks/teams.yml index 804be6e3b..5cc0079c4 100644 --- a/roles/filetree_create/tasks/teams.yml +++ b/roles/filetree_create/tasks/teams.yml @@ -53,13 +53,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/teams" - loop: >- - {{ - (teams_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | unique) + - [organization] if (teams_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | length > 0) else [] - }} + loop: "{{ (teams_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | unique) + + ([organization] if ((teams_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/filetree_create/tasks/workflow_job_templates.yml b/roles/filetree_create/tasks/workflow_job_templates.yml index 72aa95d9a..1580184d1 100644 --- a/roles/filetree_create/tasks/workflow_job_templates.yml +++ b/roles/filetree_create/tasks/workflow_job_templates.yml @@ -90,12 +90,11 @@ mode: '0755' vars: __path: "{{ output_path }}/{{ needed_path | regex_replace('/', '_') }}/workflow_job_templates/" - loop: >- - {{ (workflow_job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | - map(attribute='organization') | map(attribute='name') | list | flatten | unique) + - ([organization] if ((workflow_job_templates_lookvar | map(attribute='summary_fields') | - selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) - }} + loop: "{{ (workflow_job_templates_lookvar | map(attribute='summary_fields') | selectattr('organization', 'defined') | + map(attribute='organization') | map(attribute='name') | list | flatten | unique) + + ([organization] if ((workflow_job_templates_lookvar | map(attribute='summary_fields') | + selectattr('organization', 'undefined') | list | flatten) | length > 0) else []) + }}" loop_control: loop_var: needed_path label: "{{ __path }}" diff --git a/roles/meta_dependency_check/README.md b/roles/meta_dependency_check/README.md index c47f5d5ae..73fdc32c4 100644 --- a/roles/meta_dependency_check/README.md +++ b/roles/meta_dependency_check/README.md @@ -1,6 +1,6 @@ # infra.controller_configuration.meta_dependency_check -This role is designed to eb run before any roles in this collection to check that the underlying awx.awx or ansible.controller collection is installed. This is a dependency of together roles and does not need to be explicitly called. +This role is designed to be run before any roles in this collection to check that the underlying awx.awx or ansible.controller collection is installed. This is a dependency of together roles and does not need to be explicitly called. ## License diff --git a/roles/meta_dependency_check/defaults/main.yml b/roles/meta_dependency_check/defaults/main.yml new file mode 100644 index 000000000..5660c9b6c --- /dev/null +++ b/roles/meta_dependency_check/defaults/main.yml @@ -0,0 +1,3 @@ +--- +controller_dependency_check: true +... diff --git a/roles/meta_dependency_check/tasks/main.yml b/roles/meta_dependency_check/tasks/main.yml index 32d73989b..eec538e80 100644 --- a/roles/meta_dependency_check/tasks/main.yml +++ b/roles/meta_dependency_check/tasks/main.yml @@ -1,23 +1,33 @@ --- # tasks file for meta_dependency_check -- name: Check awx.awx is installed - ansible.builtin.command: ansible-galaxy collection verify awx.awx - failed_when: false - changed_when: false - register: upstream_dep +- name: Print dependency check status + ansible.builtin.debug: + msg: "{{ controller_dependency_check | bool | ternary(__depdency_check_active_msg, __depdency_check_inactive_msg) }}" + vars: + __depdency_check_active_msg: 'Dependency check is active. Required collections presence will be verified.' + __depdency_check_inactive_msg: 'Dependency check is deactivated. Required collections presence will not be verified. This might cause failure in the next tasks.' -- name: Check ansible.controller is installed - ansible.builtin.command: ansible-galaxy collection verify ansible.controller - failed_when: false - changed_when: false - register: downstream_dep +- name: Dependency check block + when: controller_dependency_check | bool + block: + - name: Check awx.awx is installed + ansible.builtin.command: ansible-galaxy collection verify awx.awx + failed_when: false + changed_when: false + register: upstream_dep -- name: Ensure one is installed - ansible.builtin.fail: - msg: One of awx.awx or ansible.controller must be installed - when: - - "'ERROR!' in upstream_dep.stderr" - - "'ERROR!' in downstream_dep.stderr" + - name: Check ansible.controller is installed + ansible.builtin.command: ansible-galaxy collection verify ansible.controller + failed_when: false + changed_when: false + register: downstream_dep + + - name: Ensure one is installed + ansible.builtin.fail: + msg: One of awx.awx or ansible.controller must be installed + when: + - "'ERROR!' in upstream_dep.stderr" + - "'ERROR!' in downstream_dep.stderr" ... diff --git a/tests/configure_controller.yml b/tests/configure_controller.yml index 9682edea9..91eaf491e 100644 --- a/tests/configure_controller.yml +++ b/tests/configure_controller.yml @@ -187,37 +187,4 @@ controller_host: "{{ controller_hostname }}" validate_certs: "{{ controller_validate_certs }}" ignore_errors: true # noqa ignore-errors - - - name: "Get the organization ID" - ansible.builtin.set_fact: - controller_organization_id: "{{ lookup(controller_api_plugin, 'organizations', query_params={'name': 'Default'}, host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}" - - - name: "Set empty lists for testing" - ansible.builtin.set_fact: - controller_api_results: [] - differential_test_items: [] - - - name: "Error out on empty list" - ansible.builtin.set_fact: - error_empty_diff: "{{ query('controller_object_diff', api_list=controller_api_results, compare_list=differential_test_items, warn_on_empty_api=false) }}" - ignore_errors: true - register: error_results - - - name: "Warn out on empty list" - ansible.builtin.set_fact: - warn_empty_diff: "{{ query('controller_object_diff', api_list=controller_api_results, compare_list=differential_test_items) }}" - register: warn_results - - - name: "Assert that the empty list error correctly" - ansible.builtin.assert: - that: - - error_empty_diff is not defined - - warn_empty_diff | length == 0 - - "'Unable to find items in api_list' in error_results.msg" - - - name: Differential Testing - ansible.builtin.include_tasks: "./tasks/differential.yml" - loop: "{{ differential_items }}" - loop_control: - loop_var: differential_item ...