Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tion into devel
  • Loading branch information
Tompage1994 committed Oct 2, 2024
2 parents 3d8dde3 + 6ed66b7 commit 2f3c12e
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 94 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/dependency_check_control.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- Add ability to disable dependency check
...
3 changes: 3 additions & 0 deletions changelogs/fragments/filetree_create_loop_issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fixed issue with loops that were getting always empty list of objects
11 changes: 5 additions & 6 deletions roles/filetree_create/tasks/applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
11 changes: 5 additions & 6 deletions roles/filetree_create/tasks/credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
11 changes: 5 additions & 6 deletions roles/filetree_create/tasks/job_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/tasks/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions roles/filetree_create/tasks/notification_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
11 changes: 5 additions & 6 deletions roles/filetree_create/tasks/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
12 changes: 5 additions & 7 deletions roles/filetree_create/tasks/teams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
11 changes: 5 additions & 6 deletions roles/filetree_create/tasks/workflow_job_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/meta_dependency_check/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions roles/meta_dependency_check/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
controller_dependency_check: true
...
42 changes: 26 additions & 16 deletions roles/meta_dependency_check/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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"

...
33 changes: 0 additions & 33 deletions tests/configure_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
...

0 comments on commit 2f3c12e

Please sign in to comment.