Skip to content

Commit

Permalink
Filetree create add gateway objects (redhat-cop#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarmu authored Nov 21, 2024
1 parent 0a8f2be commit 8733cd7
Show file tree
Hide file tree
Showing 63 changed files with 991 additions and 145 deletions.
12 changes: 6 additions & 6 deletions roles/filetree_create/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ A list of other roles hosted on Galaxy should go here, plus any details in regar
aap_username: "{{ vault_aap_username | default(lookup('env', 'CONTROLLER_USERNAME')) }}"
aap_password: "{{ vault_aap_password | default(lookup('env', 'CONTROLLER_PASSWORD')) }}"
aap_hostname: "{{ vault_aap_hostname | default(lookup('env', 'CONTROLLER_HOST')) }}"
controller_validate_certs: "{{ vault_controller_validate_certs | default(lookup('env', 'CONTROLLER_VERIFY_SSL')) }}"
aap_validate_certs: "{{ vault_aap_validate_certs | default(lookup('env', 'CONTROLLER_VERIFY_SSL')) }}"

pre_tasks:
- name: "Setup authentication (block)"
Expand All @@ -61,7 +61,7 @@ A list of other roles hosted on Galaxy should go here, plus any details in regar
password: "{{ aap_password }}"
method: POST
force_basic_auth: true
validate_certs: "{{ controller_validate_certs }}"
validate_certs: "{{ aap_validate_certs }}"
status_code: 201
register: authtoken_res

Expand All @@ -85,7 +85,7 @@ A list of other roles hosted on Galaxy should go here, plus any details in regar
password: "{{ aap_password }}"
method: DELETE
force_basic_auth: true
validate_certs: "{{ controller_validate_certs }}"
validate_certs: "{{ aap_validate_certs }}"
status_code: 204
when: aap_oauthtoken_url is defined
...
Expand All @@ -100,7 +100,7 @@ This role can generate output files in two different ways:
The export can be triggered with the following command:

```console
ansible-playbook -i localhost, filetree_create.yml -e '{controller_validate_certs: false, aap_hostname: localhost:8443, aap_username: admin, aap_password: password}'
ansible-playbook -i localhost, filetree_create.yml -e '{aap_validate_certs: false, aap_hostname: localhost:8443, aap_username: admin, aap_password: password}'
```

One example of this approach follows:
Expand Down Expand Up @@ -171,7 +171,7 @@ This role can generate output files in two different ways:
The expotation can be triggered with the following command:

```console
ansible-playbook -i localhost, filetree_create.yml -e '{controller_validate_certs: false, aap_hostname: localhost:8443, aap_username: admin, aap_password: password, flatten_output: true}'
ansible-playbook -i localhost, filetree_create.yml -e '{aap_validate_certs: false, aap_hostname: localhost:8443, aap_username: admin, aap_password: password, flatten_output: true}'
```

One example of this approach follows:
Expand Down Expand Up @@ -224,7 +224,7 @@ This example will export all object but some with modifications:
aap_username: "{{ vault_aap_username | default(lookup('env', 'CONTROLLER_USERNAME')) }}"
aap_oauthtoken : "{{ vault_aap_password | default(lookup('env', 'CONTROLLER_OAUTHTOKEN')) }}"
aap_hostname: "{{ vault_aap_hostname | default(lookup('env', 'CONTROLLER_HOST')) }}"
controller_validate_certs: "{{ vault_controller_validate_certs | default(lookup('env', 'CONTROLLER_VERIFY_SSL')) }}"
aap_validate_certs: "{{ vault_aap_validate_certs | default(lookup('env', 'CONTROLLER_VERIFY_SSL')) }}"

templates_overrides_resources:
job_template:
Expand Down
2 changes: 2 additions & 0 deletions roles/filetree_create/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ controller_configuration_filetree_create_secure_logging: "{{ controller_configur
input_tag:
- all
organization: 'ORGANIZATIONLESS'

query_gateway_api_max_objects: 10000
...
5 changes: 5 additions & 0 deletions roles/filetree_create/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ argument_specs:
required: false
type: int
description: Maximum number of objects to return from the list. If a list view returns more an max_objects an exception will be raised
query_gateway_api_max_objects:
default: 10000
required: false
type: int
description: Maximum number of objects to return from the list. If a list view returns more an max_objects an exception will be raised
omit_id:
default: false
required: false
Expand Down
82 changes: 62 additions & 20 deletions roles/filetree_create/tasks/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
aap_version: "{{ lookup(controller_api_plugin, 'ping',
host=aap_hostname, oauth_token=aap_oauthtoken,
verify_ssl=controller_validate_certs).version }}"
verify_ssl=aap_validate_certs).version }}"
- name: "Check if the connection is to an Ansible Tower or to Automation Platform"
ansible.builtin.set_fact:
is_aap: "{{ aap_version is version('4.0.0', '>=') }}"
Expand All @@ -20,7 +20,7 @@
organization_id: "{{ lookup(controller_api_plugin, 'organizations',
query_params={'name': organization_filter},
host=aap_hostname, oauth_token=aap_oauthtoken,
verify_ssl=controller_validate_certs).id
verify_ssl=aap_validate_certs).id
}}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

Expand All @@ -29,57 +29,99 @@
msg: "The organization {{ organization_filter }} has the ID {{ organization_id }}"

- name: Include tasks (block)
when: "['all', 'labels', 'applications', 'instance_groups', 'settings', 'inventory', 'credentials', 'credential_types', 'notification_templates', 'users', 'teams', 'roles', 'organizations', 'projects', 'execution_environments', 'job_templates', 'workflow_job_templates', 'workflow_job_template_nodes', 'schedules'] | intersect(input_tag) | length > 0"
when: "['all', 'labels', 'applications', 'instance_groups', 'settings', 'inventory', 'credentials', 'credential_types', 'notification_templates', 'users', 'teams', 'roles', 'organizations', 'projects', 'execution_environments', 'job_templates', 'workflow_job_templates', 'workflow_job_template_nodes', 'schedules', 'authenticators', 'authenticator_maps'] | intersect(input_tag) | length > 0"
block:
- name: "Export Inventories and related Groups and Hosts"
- name: "Export Controller Inventories and related Groups and Hosts"
ansible.builtin.include_tasks: "controller_inventory.yml"
when: "'inventory' in input_tag or 'all' in input_tag"
- name: "Export Constructed Inventories"
- name: "Export Controller Constructed Inventories"
ansible.builtin.include_tasks: "controller_constructed_inventory.yml"
when: "('inventory' in input_tag or 'all' in input_tag) and have_constructed"
- name: "Export Credentials"
- name: "Export Controller Credentials"
ansible.builtin.include_tasks: "controller_credentials.yml"
when: "'credentials' in input_tag or 'all' in input_tag"
- name: "Export Credential Types"
- name: "Export Controller Credential Types"
ansible.builtin.include_tasks: "controller_credential_types.yml"
when: "'credential_types' in input_tag or 'all' in input_tag"
- name: "Export Notification Templates"
- name: "Export Controller Notification Templates"
ansible.builtin.include_tasks: "controller_notification_templates.yml"
when: "'notification_templates' in input_tag or 'all' in input_tag"
- name: "Export Users"
- name: "Export Controller Users"
ansible.builtin.include_tasks: "controller_users.yml"
when: "'users' in input_tag or 'roles' in input_tag or 'all' in input_tag"
- name: "Export Teams"
- name: "Export Controller Teams"
ansible.builtin.include_tasks: "controller_teams.yml"
when: "'teams' in input_tag or 'roles' in input_tag or 'all' in input_tag"
- name: "Export Organizations"
- name: "Export Controller Organizations"
ansible.builtin.include_tasks: "controller_organizations.yml"
when: "'organizations' in input_tag or 'all' in input_tag"
- name: "Export Job Templates"
- name: "Export Controller Job Templates"
ansible.builtin.include_tasks: "controller_job_templates.yml"
when: "'job_templates' in input_tag or 'all' in input_tag"
- name: "Export Projects"
- name: "Export Controller Projects"
ansible.builtin.include_tasks: "controller_projects.yml"
when: "'projects' in input_tag or 'all' in input_tag"
- name: "Export Execution Environments"
- name: "Export Controller Execution Environments"
ansible.builtin.include_tasks: "controller_execution_environments.yml"
when: "('execution_environments' in input_tag or 'all' in input_tag) and is_aap"
- name: "Export Workflow Job Templates"
- name: "Export Controller Workflow Job Templates"
ansible.builtin.include_tasks: "controller_workflow_job_templates.yml"
when: "'workflow_job_templates' in input_tag or 'all' in input_tag"
- name: "Export Settings"
- name: "Export Controller Settings"
ansible.builtin.include_tasks: "controller_settings.yml"
when: "'settings' in input_tag or 'all' in input_tag"
- name: "Export Instance Groups"
- name: "Export Controller Instance Groups"
ansible.builtin.include_tasks: "controller_instance_groups.yml"
when: "'instance_groups' in input_tag or 'all' in input_tag"
- name: "Export Applications"
- name: "Export Controller Applications"
ansible.builtin.include_tasks: "controller_applications.yml"
when: "'applications' in input_tag or 'all' in input_tag"
- name: "Export Labels"
- name: "Export Controller Labels"
ansible.builtin.include_tasks: "controller_labels.yml"
when: "'labels' in input_tag or 'all' in input_tag"
- name: "Export Schedules"
- name: "Export Controller Schedules"
ansible.builtin.include_tasks: "controller_schedules.yml"
when: "'schedules' in input_tag or 'all' in input_tag"
- name: "Export Gateway Applications"
ansible.builtin.include_tasks: "gateway_applications.yml"
when: "'applications' in input_tag or 'all' in input_tag"
- name: "Export Gateway Authentication Maps"
ansible.builtin.include_tasks: "gateway_authenticator_maps.yml"
when: "'authenticator_maps' in input_tag or 'all' in input_tag"
- name: "Export Gateway Authentication"
ansible.builtin.include_tasks: "gateway_authenticators.yml"
when: "'authenticators' in input_tag or 'all' in input_tag"
- name: "Export Gateway HTTP Ports"
ansible.builtin.include_tasks: "gateway_http_ports.yml"
when: "'http_ports' in input_tag or 'all' in input_tag"
- name: "Export Gateway Organizations"
ansible.builtin.include_tasks: "gateway_organizations.yml"
when: "'organizations' in input_tag or 'all' in input_tag"
- name: "Export Gateway Role User Assignments"
ansible.builtin.include_tasks: "gateway_role_user_assignments.yml"
when: "'role_user_assignments' in input_tag or 'all' in input_tag"
- name: "Export Gateway Routes"
ansible.builtin.include_tasks: "gateway_routes.yml"
when: "'routes' in input_tag or 'all' in input_tag"
- name: "Export Gateway Service Clusters"
ansible.builtin.include_tasks: "gateway_service_clusters.yml"
when: "'service_clusters' in input_tag or 'all' in input_tag"
- name: "Export Gateway Service Keys"
ansible.builtin.include_tasks: "gateway_service_keys.yml"
when: "'service_keys' in input_tag or 'all' in input_tag"
- name: "Export Gateway Service Nodes"
ansible.builtin.include_tasks: "gateway_service_nodes.yml"
when: "'gateway_service_nodes' in input_tag or 'all' in input_tag"
- name: "Export Gateway Services"
ansible.builtin.include_tasks: "gateway_services.yml"
when: "'gateway_services' in input_tag or 'all' in input_tag"
- name: "Export Gateway Settings"
ansible.builtin.include_tasks: "gateway_settings.yml"
when: "'gateway_settings' in input_tag or 'all' in input_tag"
- name: "Export Gateway Teams"
ansible.builtin.include_tasks: "gateway_teams.yml"
when: "'gateway_teams' in input_tag or 'all' in input_tag"
- name: "Export Gateway Users"
ansible.builtin.include_tasks: "gateway_users.yml"
when: "'gateway_users' in input_tag or 'all' in input_tag"
...
2 changes: 1 addition & 1 deletion roles/filetree_create/tasks/controller_applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
applications_lookvar: "{{ query(controller_api_plugin, 'applications/',
query_params=(query_params | combine({'organization': organization_id})) if organization_id is defined else query_params,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
vars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
constructed_inventory_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/constructed_inventories/',
query_params=(query_params | combine({'organization': organization_id})) if organization_id is defined else query_params,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
vars:
Expand Down
4 changes: 2 additions & 2 deletions roles/filetree_create/tasks/controller_credential_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
credential_types_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/credential_types/',
query_params={'managed': false},
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"
Expand All @@ -13,7 +13,7 @@
ansible.builtin.set_fact:
credential_types_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/credential_types/',
query_params={'managed_by_tower': false},
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/tasks/controller_credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
credentials_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/credentials/',
query_params=(query_params | combine({'organization': organization_id})) if organization_id is defined else query_params,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
vars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
execution_environments_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/execution_environments/',
query_params=(query_params | combine({'organization': organization_id})) if organization_id is defined else query_params,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
vars:
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/tasks/controller_instance_groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: "Get current Instance Groups from the API"
ansible.builtin.set_fact:
instance_groups_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/instance_groups/',
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"
Expand Down
8 changes: 4 additions & 4 deletions roles/filetree_create/tasks/controller_inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
inventory_lookvar: "{{ query(controller_api_plugin, 'api/controller/v2/inventories/',
query_params=(query_params | combine({'organization': organization_id} if organization_id is defined else {},
{'id': inventory_id} if inventory_id is defined else {})),
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
}}"
vars:
Expand Down Expand Up @@ -99,7 +99,7 @@
else
output_path + '/inventory_sources.yaml' }}"
current_inventory_sources_asset_value: "{{ query(controller_api_plugin, current_inventory_sources.related.inventory_sources,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
if current_inventory_sources.has_inventory_sources else []
}}"
Expand All @@ -123,7 +123,7 @@
output_path + '/controller_hosts.yaml' }}"
current_hosts_asset_value: "{{ query(controller_api_plugin, current_inventory_hosts.related.hosts,
query_params={'not__description': 'imported'},
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects)
if not current_inventory_hosts.has_inventory_sources else []
}}"
Expand All @@ -146,7 +146,7 @@
output_path + '/groups.yaml' }}"
current_groups_asset_value: "{{ query(controller_api_plugin, current_inventory_groups.related.groups,
query_params={'not__description': 'imported'},
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=aap_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 []
}}"
Expand Down
Loading

0 comments on commit 8733cd7

Please sign in to comment.