From 726b31f5e383e0fb41dbc9719d98215dd966d728 Mon Sep 17 00:00:00 2001 From: Hamza Date: Wed, 25 Sep 2024 17:02:21 +0200 Subject: [PATCH 1/3] Give the user the possibility to deactivate dependency check (#911) * fix typo * Give the user the possibility to deactivate dependency check * Create dependency_check_control.yml --------- Co-authored-by: Tom Page Co-authored-by: Tom Page --- .../fragments/dependency_check_control.yml | 4 ++ roles/meta_dependency_check/README.md | 2 +- roles/meta_dependency_check/defaults/main.yml | 3 ++ roles/meta_dependency_check/tasks/main.yml | 42 ++++++++++++------- 4 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 changelogs/fragments/dependency_check_control.yml create mode 100644 roles/meta_dependency_check/defaults/main.yml 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/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" ... From 06c5ec9f14e1e47228bb8f33b905393345e491a6 Mon Sep 17 00:00:00 2001 From: Jesse Wattenbarger Date: Thu, 26 Sep 2024 09:43:49 -0400 Subject: [PATCH 2/3] remove failing and flakey tests (#905) These tests were failing or flakey when run against an awx devel installation. This PR removes them and makes `ansible-playbook tests/configure_controller.yml` work correctly and run with passes. Co-authored-by: Tom Page Co-authored-by: David Danielsson --- tests/configure_controller.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) 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 ... From 6ed66b77d58df3aba1ca91c0d6b443e9a0bc9ea0 Mon Sep 17 00:00:00 2001 From: przemkalit Date: Tue, 1 Oct 2024 17:15:00 +0200 Subject: [PATCH 3/3] Fix issue with looping over always empty list (#920) * fix: loop issue * fix: loop issue part2 * fix: missing brackets --------- Co-authored-by: Przemyslaw Kalitowski --- changelogs/fragments/filetree_create_loop_issue.yaml | 3 +++ roles/filetree_create/tasks/applications.yml | 11 +++++------ roles/filetree_create/tasks/credentials.yml | 11 +++++------ roles/filetree_create/tasks/job_templates.yml | 11 +++++------ roles/filetree_create/tasks/labels.yml | 2 +- .../filetree_create/tasks/notification_templates.yml | 11 +++++------ roles/filetree_create/tasks/projects.yml | 11 +++++------ roles/filetree_create/tasks/teams.yml | 12 +++++------- .../filetree_create/tasks/workflow_job_templates.yml | 11 +++++------ 9 files changed, 39 insertions(+), 44 deletions(-) create mode 100644 changelogs/fragments/filetree_create_loop_issue.yaml 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 }}"