Skip to content

Commit

Permalink
Merge branch 'devel' into constructed_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
djdanielsson authored Nov 2, 2023
2 parents 8340be5 + a20e97c commit 19dcf49
Show file tree
Hide file tree
Showing 36 changed files with 278 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- filetree_create - Add the constructed inventory exportation fields from the API endpoint `api/v2/constructed_inventories`
9 changes: 7 additions & 2 deletions roles/applications/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
loop_var: "__application_item"
label: "{{ __operation.verb }} Controller Application {{ __application_item.name }}"
no_log: "{{ controller_configuration_applications_secure_logging }}"
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __applications_job_async
changed_when: not __applications_job_async.changed
vars:
__operation: "{{ operation_translate[__application_item.state | default(controller_state) | default('present')] }}"
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __applications_job_async.failed is defined and __applications_job_async.failed

- name: "Managing Controller Applications | Wait for finish the Application management"
ansible.builtin.async_status:
jid: "{{ __applications_job_async_results_item.ansible_job_id }}"
Expand All @@ -44,7 +49,7 @@
loop_control:
loop_var: __applications_job_async_results_item
label: "{{ __operation.verb }} Controller Application {{ __applications_job_async_results_item.__application_item.name }} | Wait for finish the Application {{ __operation.action }}"
when: __applications_job_async_results_item.ansible_job_id is defined
when: not ansible_check_mode and __applications_job_async_results_item.ansible_job_id is defined
no_log: "{{ controller_configuration_applications_secure_logging }}"
vars:
__operation: "{{ operation_translate[__applications_job_async_results_item.__application_item.state | default(controller_state) | default('present')] }}"
Expand Down
9 changes: 7 additions & 2 deletions roles/bulk_host_create/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
loop_control:
loop_var: __controller_bulk_hosts_item
no_log: "{{ controller_configuration_bulk_hosts_secure_logging }}"
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __controller_bulk_hosts_job_async
changed_when: not __controller_bulk_hosts_job_async.changed
vars:
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __controller_bulk_hosts_job_async.failed is defined and __controller_bulk_hosts_job_async.failed

- name: "Configure bulk_hosts | Wait for finish the bulk_hosts creation"
ansible.builtin.async_status:
jid: "{{ __controller_bulk_hosts_job_async_results_item.ansible_job_id }}"
Expand All @@ -34,7 +39,7 @@
loop: "{{ __controller_bulk_hosts_job_async.results }}"
loop_control:
loop_var: __controller_bulk_hosts_job_async_results_item
when: __controller_bulk_hosts_job_async_results_item.ansible_job_id is defined
when: not ansible_check_mode and __controller_bulk_hosts_job_async_results_item.ansible_job_id is defined
no_log: "{{ controller_configuration_bulk_hosts_secure_logging }}"
vars:
ansible_async_dir: '{{ controller_configuration_async_dir }}'
Expand Down
1 change: 1 addition & 0 deletions roles/bulk_job_launch/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
loop: "{{ controller_bulk_launch_jobs }}"
loop_control:
loop_var: "__bulk_job_launch_item"
label: "{{ (__bulk_job_launch_item.organization | default('<no_org>')) }}/{{ __bulk_job_launch_item.name }}"
no_log: "{{ controller_configuration_bulk_job_launch_secure_logging }}"
register: bulk_launched_controller_jobs
when: controller_bulk_launch_jobs is defined
Expand Down
9 changes: 7 additions & 2 deletions roles/credential_input_sources/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
loop_var: "__cred_input_src_item"
label: "{{ __operation.verb }} Controller Credential Input Source for Credential {{ __cred_input_src_item.target_credential }}"
no_log: "{{ controller_configuration_credential_input_sources_secure_logging }}"
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __credential_input_sources_job_async
changed_when: not __credential_input_sources_job_async.changed
vars:
__operation: "{{ operation_translate[__cred_input_src_item.state | default(controller_state) | default('present')] }}"
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __credential_input_sources_job_async.failed is defined and __credential_input_sources_job_async.failed

- name: "Managing Controller Credential Input Sources | Wait for finish the Controller Credential Input Sources management"
ansible.builtin.async_status:
jid: "{{ __credential_input_sources_job_async_results_item.ansible_job_id }}"
Expand All @@ -40,7 +45,7 @@
loop_control:
loop_var: __credential_input_sources_job_async_results_item
label: "{{ __operation.verb }} Controller Credential Input Source for Credential {{ __credential_input_sources_job_async_results_item.__cred_input_src_item.target_credential }}"
when: __credential_input_sources_job_async_results_item.ansible_job_id is defined
when: not ansible_check_mode and __credential_input_sources_job_async_results_item.ansible_job_id is defined
no_log: "{{ controller_configuration_credential_input_sources_secure_logging }}"
vars:
__operation: "{{ operation_translate[__credential_input_sources_job_async_results_item.__cred_input_src_item.state | default(controller_state) | default('present')] }}"
Expand Down
9 changes: 7 additions & 2 deletions roles/credential_types/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
loop_var: __controller_credential_type_item
label: "{{ __operation.verb }} Credential Type {{ __controller_credential_type_item.name }}"
no_log: "{{ controller_configuration_credential_types_secure_logging }}"
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __credentialtypes_job_async
changed_when: not __credentialtypes_job_async.changed
vars:
__operation: "{{ operation_translate[__controller_credential_type_item.state | default(controller_state) | default('present')] }}"
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __credentialtypes_job_async.failed is defined and __credentialtypes_job_async.failed

- name: "Managing Controller Credential Types | Wait for finish the credential types management"
ansible.builtin.async_status:
jid: "{{ __credentialtypes_job_async_result_item.ansible_job_id }}"
Expand All @@ -41,7 +46,7 @@
loop_control:
loop_var: __credentialtypes_job_async_result_item
label: "{{ __operation.verb }} Controller Credential Type {{ __credentialtypes_job_async_result_item }} | Wait for finish the credential type {{ __operation.action }}"
when: __credentialtypes_job_async_result_item.ansible_job_id is defined
when: not ansible_check_mode and __credentialtypes_job_async_result_item.ansible_job_id is defined
no_log: "{{ controller_configuration_credential_types_secure_logging }}"
vars:
__operation: "{{ operation_translate[__credentialtypes_job_async_result_item.__controller_credential_type_item.state | default(controller_state) | default('present')] }}"
Expand Down
9 changes: 7 additions & 2 deletions roles/credentials/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
loop_var: __controller_credentials_item
label: "{{ __operation.verb }} Credential {{ __controller_credentials_item.name }}"
no_log: "{{ controller_configuration_credentials_secure_logging }}"
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __credentials_job_async
changed_when: not __credentials_job_async.changed
vars:
__operation: "{{ operation_translate[__controller_credentials_item.state | default(controller_state) | default('present')] }}"
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __credentials_job_async.failed is defined and __credentials_job_async.failed

- name: "Managing Controller Credentials | Wait for finish the credential management"
ansible.builtin.async_status:
jid: "{{ __credentials_job_async_results_item.ansible_job_id }}"
Expand All @@ -44,7 +49,7 @@
loop_control:
loop_var: __credentials_job_async_results_item
label: "{{ __operation.verb }} Credential {{ __credentials_job_async_results_item.__controller_credentials_item.name }} | Wait for finish the credential {{ __operation.action }}"
when: __credentials_job_async_results_item.ansible_job_id is defined
when: not ansible_check_mode and __credentials_job_async_results_item.ansible_job_id is defined
no_log: "{{ controller_configuration_credentials_secure_logging }}"
vars:
__operation: "{{ operation_translate[__controller_credentials_item.state | default(controller_state) | default('present')] }}"
Expand Down
5 changes: 5 additions & 0 deletions roles/dispatch/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
vars:
assign_galaxy_credentials_to_org: "{{ __role.assign_galaxy_credentials_to_org | default(false) }}"
assign_default_ee_to_org: "{{ __role.assign_default_ee_to_org | default(false) }}"

- name: "Fail the playbook if there were errors (check mode only)"
ansible.builtin.fail:
msg: "The execution has failed because of errors (probably due to missing dependencies caused by check mode)."
when: ansible_check_mode and error_flag is defined and error_flag
...
9 changes: 7 additions & 2 deletions roles/execution_environments/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
label: "{{ __operation.verb }} Controller Execution Environment {{ __execution_environments_item }}"
no_log: "{{ controller_configuration_execution_environments_secure_logging }}"
when: controller_execution_environments is defined
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __execution_environments_job_async
changed_when: not __execution_environments_job_async.changed
vars:
__operation: "{{ operation_translate[__execution_environments_item.state | default(controller_state) | default('present')] }}"
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __execution_environments_job_async.failed is defined and __execution_environments_job_async.failed

- name: "Managing Controller Execution Environments | Wait for finish the Controller Execution Environments management"
ansible.builtin.async_status:
jid: "{{ __execution_environments_job_async_results_item.ansible_job_id }}"
Expand All @@ -44,7 +49,7 @@
loop_control:
loop_var: __execution_environments_job_async_results_item
label: "{{ __operation.verb }} Controller Execution Environment {{ __execution_environments_job_async_results_item.__execution_environments_item.name }} | Wait for finish the Controller Execution Environment {{ __operation.action }}"
when: __execution_environments_job_async_results_item.ansible_job_id is defined
when: not ansible_check_mode and __execution_environments_job_async_results_item.ansible_job_id is defined
no_log: "{{ controller_configuration_execution_environments_secure_logging }}"
vars:
__operation: "{{ operation_translate[__execution_environments_job_async_results_item.__execution_environments_item.state | default(controller_state) | default('present')] }}"
Expand Down
3 changes: 3 additions & 0 deletions roles/filetree_create/tasks/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
- name: "Export Inventories and related Groups and Hosts"
ansible.builtin.include_tasks: "inventory.yml"
when: "'inventory' in input_tag or 'all' in input_tag"
- name: "Export Constructed Inventories"
ansible.builtin.include_tasks: "constructed_inventory.yml"
when: "'inventory' in input_tag or 'all' in input_tag"
- name: "Export Credentials"
ansible.builtin.include_tasks: "credentials.yml"
when: "'credentials' in input_tag or 'all' in input_tag"
Expand Down
41 changes: 41 additions & 0 deletions roles/filetree_create/tasks/constructed_inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: "Get the inventories from the API"
ansible.builtin.set_fact:
constructed_inventory_lookvar: "{{ query(controller_api_plugin, 'api/v2/constructed_inventories/',
query_params=(query_params | combine({'organization': organization_id})) if organization_id is defined else query_params,
host=controller_hostname, oauth_token=controller_oauthtoken, verify_ssl=controller_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
vars:
query_params:
order_by: 'organization,id'
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Create the <ORGANIZATION_NAME>/inventories output directory for inventories in {{ output_path }}"
ansible.builtin.file:
path: "{{ __path }}"
state: directory
mode: '0755'
vars:
inventory_organization: "{{ needed_path.summary_fields.organization.name | default('ORGANIZATIONLESS') }}"
inventory_name: "{{ needed_path.name | regex_replace('/', '_') }}"
__path: "{{ output_path }}/{{ inventory_organization | regex_replace('/', '_') }}/inventories/{{ inventory_name | regex_replace('/', '_') }}"
loop: "{{ constructed_inventory_lookvar }}"
loop_control:
loop_var: needed_path
label: "{{ __path }}"

- name: "Add current constructed_inventories to the <ORGANIZATION_NAME>/inventories output yaml file in {{ output_path }}"
ansible.builtin.template:
src: "templates/current_inventories.j2"
dest: "{{ __dest }}"
mode: '0644'
vars:
inventory_organization: "{{ current_inventories_asset_value.summary_fields.organization.name | default('ORGANIZATIONLESS') }}"
inventory_name: "{{ current_inventories_asset_value.name | regex_replace('/', '_') }}"
__dest: "{{ output_path }}/{{ inventory_organization | regex_replace('/', '_') }}/inventories/{{ inventory_name | regex_replace('/', '_') }}/{{ current_inventories_asset_value.id }}_{{ inventory_name | regex_replace('/', '_') }}.yaml"
loop: "{{ constructed_inventory_lookvar }}"
loop_control:
loop_var: current_inventories_asset_value
label: "{{ __dest }}"
...
9 changes: 5 additions & 4 deletions roles/filetree_create/tasks/inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}}"
vars:
query_params:
not__kind: 'smart'
not__kind: 'constructed'
order_by: 'organization,id'
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

Expand Down Expand Up @@ -76,14 +76,15 @@

- name: "Set the inventory's groups"
ansible.builtin.include_tasks: "groups.yml"
when: current_inventory_groups.total_groups > 0
vars:
inventory_organization: "{{ current_inventory_groups.summary_fields.organization.name | default('ORGANIZATIONLESS') }}"
inventory_name: "{{ current_inventory_groups.name | regex_replace('/', '_') }}"
groups_output_path: "{{ output_path }}/{{ inventory_organization | regex_replace('/', '_') }}/inventories/{{ inventory_name | regex_replace('/', '_') }}"
current_groups_asset_value: "{{ query(controller_api_plugin, current_inventory_groups.related.groups,
host=controller_hostname, oauth_token=controller_oauthtoken, verify_ssl=controller_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
if not current_inventory_groups.has_inventory_sources else []
host=controller_hostname, oauth_token=controller_oauthtoken, verify_ssl=controller_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
if (not current_inventory_groups.has_inventory_sources or current_inventory_groups.kind is match('smart')) else []
}}"
loop: "{{ inventory_lookvar }}"
loop_control:
Expand Down
20 changes: 18 additions & 2 deletions roles/filetree_create/templates/current_inventories.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@ controller_inventories:
- name: "{{ current_inventories_asset_value.name }}"
description: "{{ current_inventories_asset_value.description }}"
organization: "{{ inventory_organization }}"
{% if current_inventories_asset_value.host_filter %}
{% if current_inventories_asset_value.host_filter is defined %}
host_filter: "{{ current_inventories_asset_value.host_filter }}"
{% endif %}
{% if current_inventories_asset_value.kind %}
kind: "{{ current_inventories_asset_value.kind }}"
{% endif %}
{% if current_inventories_asset_value.variables and current_inventories_asset_value.variables != '---' and current_inventories_asset_value.variables != '' %}
{% if current_inventories_asset_value.prevent_instance_group_fallback is defined %}
prevent_instance_group_fallback: {{ current_inventories_asset_value.prevent_instance_group_fallback }}
{% endif %}
{% if current_inventories_asset_value.source_vars is defined %}
source_vars:
{{ current_inventories_asset_value.source_vars | from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{% endif %}
{% if current_inventories_asset_value.update_cache_timeout is defined %}
update_cache_timeout: {{ current_inventories_asset_value.update_cache_timeout }}
{% endif %}
{% if current_inventories_asset_value.limit is defined %}
limit: "{{ current_inventories_asset_value.limit }}"
{% endif %}
{% if current_inventories_asset_value.verbosity is defined %}
verbosity: {{ current_inventories_asset_value.verbosity }}
{% endif %}
{% if current_inventories_asset_value.variables is defined and current_inventories_asset_value.variables != '---' and current_inventories_asset_value.variables != '' %}
variables:
{{ current_inventories_asset_value.variables | from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/current_users.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ controller_user_accounts:
last_name: "{{ current_users_asset_value.last_name }}"
auditor: "{{ current_users_asset_value.is_system_auditor }}"
superuser: "{{ current_users_asset_value.is_superuser }}"
update_secrets: False
update_secrets: false
...
9 changes: 7 additions & 2 deletions roles/groups/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@
loop_var: __controller_groups_item
label: "{{ __operation.verb }} Controller Group {{ __controller_groups_item.name }}"
no_log: "{{ controller_configuration_group_secure_logging }}"
async: 1000
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
poll: 0
register: __group_job_async
changed_when: not __group_job_async.changed
vars:
__operation: "{{ operation_translate[__controller_groups_item.state | default(controller_state) | default('present')] }}"
ansible_async_dir: '{{ controller_configuration_async_dir }}'

- name: "Flag for errors (check mode only)"
ansible.builtin.set_fact:
error_flag: true
when: ansible_check_mode and __group_job_async.failed is defined and __group_job_async.failed

- name: "Managing Controller Groups | Wait for finish the Controller Groups management"
ansible.builtin.async_status:
jid: "{{ __group_job_async_results_item.ansible_job_id }}"
Expand All @@ -46,7 +51,7 @@
loop_control:
loop_var: __group_job_async_results_item
label: "{{ __operation.verb }} Controller Group {{ __group_job_async_results_item.__controller_groups_item.name }} | Wait for finish the Controller Group {{ __operation.action }}"
when: __group_job_async_results_item.ansible_job_id is defined
when: not ansible_check_mode and __group_job_async_results_item.ansible_job_id is defined
no_log: "{{ controller_configuration_group_secure_logging }}"
vars:
__operation: "{{ operation_translate[__group_job_async_results_item.__controller_groups_item.state | default(controller_state) | default('present')] }}"
Expand Down
Loading

0 comments on commit 19dcf49

Please sign in to comment.