Skip to content

Commit e81ea8e

Browse files
Restucture the gateway_organizations role so that only one role needs to be called to create and configure the organization (#1054)
Co-authored-by: David Danielsson <djdanielsson@users.noreply.github.com>
1 parent 1d4dce3 commit e81ea8e

File tree

8 files changed

+143
-37
lines changed

8 files changed

+143
-37
lines changed

.markdownlint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ MD0046:
1818
MD033:
1919
allowed_elements:
2020
- br
21+
- a
22+
- img
2123
...
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
major_changes:
3+
- Restucture the gateway_organizations role so that only one role needs to be called to create and configure the organization. Adds the logic which existed from the controller_organizations role previously.
4+
- Dispatch no longer calls the controller_organizations role by default, as the gateway_organizations role should be sufficient.
5+
...

roles/controller_organizations/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
An Ansible Role to create/update/remove Organizations on Ansible Controller.
5+
An Ansible Role to create/update/remove Organizations on Ansible Controller. Note that this role will not create organizations in AAP 2.5 and beyond. Instead, make use of the `gateway_organizations` role from this collection.
66

77
## Requirements
88

roles/dispatch/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ gateway_configuration_dispatcher_roles:
4141
- role: gateway_organizations
4242
var: aap_organizations
4343
tags: organizations
44+
assign_galaxy_credentials_to_org: false
45+
assign_default_ee_to_org: false
46+
assign_notification_templates_to_org: false
4447
- role: gateway_service_clusters
4548
var: gateway_service_clusters
4649
tags: service_clusters
@@ -116,12 +119,6 @@ controller_configuration_dispatcher_roles:
116119
- role: controller_settings
117120
var: controller_settings
118121
tags: settings
119-
- role: controller_organizations
120-
var: aap_organizations
121-
tags: organizations
122-
assign_galaxy_credentials_to_org: false
123-
assign_default_ee_to_org: false
124-
assign_notification_templates_to_org: false
125122
- role: controller_instances
126123
var: controller_instances
127124
tags: instances
@@ -149,7 +146,7 @@ controller_configuration_dispatcher_roles:
149146
- role: controller_notification_templates
150147
var: controller_notifications
151148
tags: notification_templates
152-
- role: controller_organizations
149+
- role: gateway_organizations
153150
var: aap_organizations
154151
tags: organizations
155152
assign_galaxy_credentials_to_org: true

roles/dispatch/defaults/main.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ gateway_configuration_dispatcher_roles:
1212
- role: gateway_organizations
1313
var: aap_organizations
1414
tags: organizations
15+
assign_galaxy_credentials_to_org: false
16+
assign_default_ee_to_org: false
17+
assign_notification_templates_to_org: false
1518
- role: gateway_applications
1619
var: aap_applications
1720
tags: applications
@@ -85,12 +88,6 @@ controller_configuration_dispatcher_roles:
8588
- role: controller_settings
8689
var: controller_settings
8790
tags: settings
88-
- role: controller_organizations
89-
var: aap_organizations
90-
tags: organizations
91-
assign_galaxy_credentials_to_org: false
92-
assign_default_ee_to_org: false
93-
assign_notification_templates_to_org: false
9491
- role: controller_instances
9592
var: controller_instances
9693
tags: instances
@@ -118,7 +115,7 @@ controller_configuration_dispatcher_roles:
118115
- role: controller_notification_templates
119116
var: controller_notifications
120117
tags: notification_templates
121-
- role: controller_organizations
118+
- role: gateway_organizations
122119
var: aap_organizations
123120
tags: organizations
124121
assign_galaxy_credentials_to_org: true

roles/gateway_organizations/README.md

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
An Ansible Role to add Organizations on Ansible Automation gateway.
66

7+
## Requirements
8+
9+
This role requires both `ansible.platform` and `ansible.controller` collections. Note that the `awx.awx` collection will not work with this role. See the `controller_organizations` role for the AWX/Controller only implementation.
10+
711
## Variables
812

913
|Variable Name|Default Value|Required|Description|Example|
@@ -16,6 +20,26 @@ An Ansible Role to add Organizations on Ansible Automation gateway.
1620
|`aap_token`|""|no|Controller Admin User's token on the Ansible Automation Platform Server. This should be stored in an Ansible Vault at or elsewhere and called from a parent playbook. Either username / password or oauthtoken need to be specified.||
1721
|`aap_request_timeout`|`10`|no|Specify the timeout in seconds Ansible should use in requests to the Ansible Automation Platform host.||
1822
|`aap_organizations`|`see below`|yes|Data structure describing your organizations Described below.||
23+
|`assign_galaxy_credentials_to_org`|`true`|no|Boolean to indicate whether credentials should be assigned or not. It should be noted that credentials must exist before adding it. The dispatch role will set this to `false`, before re-running the role with it set to `true`. ||
24+
|`assign_default_ee_to_org`|`true`|no|Boolean to indicate whether default execution environment should be assigned or not. It should be noted that execution environment must exist before adding it. The dispatch role will set this to `false`, before re-running the role with it set to `true`. ||
25+
|`assign_notification_templates_to_org`|`true`|no|Boolean to indicate whether notification templates should be assigned or not. It should be noted that the templates must exist before adding them. The dispatch role will set this to `false`, before re-running the role with it set to `true`. ||
26+
|`assign_instance_groups_to_org`|`true`|no|Boolean to indicate whether an instance group should be assigned or not. It should be noted that the instance group must exist before adding it. ||
27+
28+
### Enforcing defaults
29+
30+
The following Variables compliment each other.
31+
If Both variables are not set, enforcing default values is not done.
32+
Enabling these variables enforce default values on options that are optional in the controller API.
33+
This should be enabled to enforce configuration and prevent configuration drift. It is recommended to be enabled, however it is not enforced by default.
34+
35+
Enabling this will enforce configuration without specifying every option in the configuration files.
36+
37+
'gateway_organizations_enforce_defaults' defaults to the value of 'aap_configuration_enforce_defaults' if it is not explicitly called. This allows for enforced defaults to be toggled for the entire suite of controller configuration roles with a single variable, or for the user to selectively use it.
38+
39+
|Variable Name|Default Value|Required|Description|
40+
|:---:|:---:|:---:|:---:|
41+
|`gateway_organizations_enforce_defaults`|`false`|no|Whether or not to enforce default option values on only the applications role|
42+
|`aap_configuration_enforce_defaults`|`false`|no|This variable enables enforced default values as well, but is shared across multiple roles, see above.|
1943

2044
### Secure Logging Variables
2145

@@ -52,12 +76,21 @@ This also speeds up the overall role.
5276

5377
Options for the `aap_organizations` variable:
5478

55-
| Variable Name | Default Value | Required | Type | Description |
56-
|:--------------|:-------------:|:--------:|:----:|:---------------------------------------------------------------------------------|
57-
| `name` | N/A | yes | str | The name of the resource |
58-
| `new_name` | N/A | no | str | Setting this option will change the existing name (looked up via the name field) |
59-
| `description` | N/A | no | str | Description of the organization |
60-
| `state` | `present` | no | str | Desired state of the resource. |
79+
| Variable Name | Default Value | Required | Type | Description |
80+
|:-----------------------------------|:-------------:|:--------:|:----:|:---------------------------------------------------------------------------------|
81+
| `name` | N/A | yes | str | The name of the resource |
82+
| `new_name` | N/A | no | str | Setting this option will change the existing name (looked up via the name field) |
83+
| `description` | N/A | no | str | Description of the organization |
84+
| `custom_virtualenv` | N/A | no | str | Local absolute file path containing a custom Python virtualenv to use. |
85+
| `max_hosts` | N/A | no | int | The max hosts allowed in this organization. |
86+
| `instance_groups` | N/A | no | list | list of Instance Groups for this Organization to run on. |
87+
| `galaxy_credentials` | N/A | no | list | The credentials to use with private automation hub. |
88+
| `default_environment` | N/A | no | str | Default Execution Environment to use for jobs owned by the Organization. |
89+
| `notification_templates_started` | N/A | no | list | The notifications on started to use for this organization in a list. |
90+
| `notification_templates_success` | N/A | no | list | The notifications on success to use for this organization in a list. |
91+
| `notification_templates_error` | N/A | no | list | The notifications on error to use for this organization in a list. |
92+
| `notification_templates_approvals` | N/A | no | list | The notifications for approval to use for this organization in a list. |
93+
| `state` | `present` | no | str | Desired state of the resource. |
6194

6295
### Unique value
6396

@@ -71,15 +104,22 @@ Options for the `aap_organizations` variable:
71104

72105
```json
73106
{
74-
"aap_organizations": [
75-
{
76-
"name": "Org 1",
77-
"description": "First Organization"
78-
},
79-
{
80-
"name": "Org 2"
81-
}
82-
]
107+
"aap_organizations": [
108+
{
109+
"name": "Default",
110+
"description": "This is the Default Group"
111+
},
112+
{
113+
"name": "Automation Group",
114+
"description": "This is the Automation Group",
115+
"custom_virtualenv": "/opt/cust/environment/",
116+
"max_hosts": 10,
117+
"galaxy_credentials": "Automation Hub",
118+
"notification_templates_error": [
119+
"Slack_for_testing"
120+
]
121+
}
122+
]
83123
}
84124
```
85125

@@ -95,13 +135,12 @@ File name: `data/aap_organizations.yml`
95135
```yaml
96136
---
97137
aap_organizations:
98-
- name: "Deprecated Org"
99-
state: absent
100-
- name: Org 1
101-
state: exists
102-
- name: Org 2
103-
- name: Org 3
104-
new_name: Organization 3
138+
- name: Default
139+
description: This is the Default Group
140+
- name: Automation Group
141+
description: This is the Automation Group
142+
custom_virtualenv: "/opt/cust/environment/"
143+
max_hosts: 10
105144
```
106145
107146
### Run Playbook

roles/gateway_organizations/defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@ gateway_organizations_secure_logging: "{{ aap_configuration_secure_logging | def
1414
gateway_organizations_async_retries: "{{ aap_configuration_async_retries | default(30) }}"
1515
gateway_organizations_async_delay: "{{ aap_configuration_async_delay | default(1) }}"
1616
gateway_organizations_loop_delay: "{{ aap_configuration_loop_delay | default(0) }}"
17+
gateway_organizations_enforce_defaults: "{{ aap_configuration_enforce_defaults | default(false) }}"
1718
aap_configuration_async_dir:
19+
20+
assign_galaxy_credentials_to_org: true
21+
assign_default_ee_to_org: true
22+
assign_notification_templates_to_org: true
23+
assign_instance_groups_to_org: true
1824
...

roles/gateway_organizations/tasks/main.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,64 @@
4343
vars:
4444
__operation: "{{ operation_translate[__gateway_organizations_job_async_results_item.state | default(platform_state) | default('present')] }}"
4545
ansible_async_dir: "{{ aap_configuration_async_dir }}"
46+
47+
- name: Organizations | Controller Configuration
48+
ansible.controller.organization:
49+
name: "{{ __controller_organizations_item.name | mandatory }}"
50+
new_name: "{{ __controller_organizations_item.new_name | default(omit) }}"
51+
description: "{{ __controller_organizations_item.description | default(('' if gateway_organizations_enforce_defaults else omit), true) }}"
52+
custom_virtualenv: "{{ __controller_organizations_item.custom_virtualenv | default(omit, true) }}"
53+
max_hosts: "{{ __controller_organizations_item.max_hosts | default((0 if gateway_organizations_enforce_defaults else omit), true) }}"
54+
instance_groups: "{{ (__controller_organizations_item.instance_groups | default(([] if gateway_organizations_enforce_defaults else omit), true))if (assign_instance_groups_to_org is defined and assign_instance_groups_to_org) else omit }}"
55+
default_environment: "{{ (__controller_organizations_item.default_environment.name | default(__controller_organizations_item.default_environment | default(__controller_organizations_item.execution_environment | default(omit)))) if (assign_default_ee_to_org is defined and assign_default_ee_to_org) else omit }}"
56+
galaxy_credentials: "{{ (__controller_organizations_item.galaxy_credentials | default(([] if gateway_organizations_enforce_defaults else omit), true)) if (assign_galaxy_credentials_to_org is defined and assign_galaxy_credentials_to_org) else omit }}"
57+
notification_templates_approvals: "{{ (__controller_organizations_item.related.notification_templates_approvals | map(attribute='name') | list if __controller_organizations_item.related.notification_templates_approvals is defined) | default(__controller_organizations_item.notification_templates_approvals) | default(([] if gateway_organizations_enforce_defaults else omit), true) if (assign_notification_templates_to_org is defined and assign_notification_templates_to_org) else omit }}"
58+
notification_templates_started: "{{ (__controller_organizations_item.related.notification_templates_started | map(attribute='name') | list if __controller_organizations_item.related.notification_templates_started is defined) | default(__controller_organizations_item.notification_templates_started) | default(([] if gateway_organizations_enforce_defaults else omit), true) if (assign_notification_templates_to_org is defined and assign_notification_templates_to_org) else omit }}"
59+
notification_templates_success: "{{ (__controller_organizations_item.related.notification_templates_success | map(attribute='name') | list if __controller_organizations_item.related.notification_templates_success is defined) | default(__controller_organizations_item.notification_templates_success) | default(([] if gateway_organizations_enforce_defaults else omit), true) if (assign_notification_templates_to_org is defined and assign_notification_templates_to_org) else omit }}"
60+
notification_templates_error: "{{ (__controller_organizations_item.related.notification_templates_error | map(attribute='name') | list if __controller_organizations_item.related.notification_templates_error is defined) | default(__controller_organizations_item.notification_templates_error) | default(([] if gateway_organizations_enforce_defaults else omit), true) if (assign_notification_templates_to_org is defined and assign_notification_templates_to_org) else omit }}"
61+
state: "{{ __controller_organizations_item.state | default(platform_state | default('present')) }}"
62+
63+
# Role Standard Options
64+
controller_username: "{{ aap_username | default(omit, true) }}"
65+
controller_password: "{{ aap_password | default(omit, true) }}"
66+
controller_oauthtoken: "{{ aap_token | default(omit, true) }}"
67+
request_timeout: "{{ aap_request_timeout | default(omit, true) }}"
68+
controller_host: "{{ aap_hostname | default(omit, true) }}"
69+
validate_certs: "{{ aap_validate_certs | default(omit) }}"
70+
loop: "{{ aap_organizations }}"
71+
loop_control:
72+
loop_var: __controller_organizations_item
73+
label: "{{ __operation.verb }} organization {{ __controller_organizations_item.name }}"
74+
pause: "{{ gateway_organizations_loop_delay }}"
75+
no_log: "{{ gateway_organizations_secure_logging }}"
76+
async: "{{ ansible_check_mode | ternary(0, 1000) }}"
77+
poll: 0
78+
register: __organizations_job_async
79+
changed_when: (__organizations_job_async.changed if ansible_check_mode else false)
80+
vars:
81+
__operation: "{{ operation_translate[__controller_organizations_item.state | default(platform_state) | default('present')] }}"
82+
ansible_async_dir: "{{ aap_configuration_async_dir }}"
83+
84+
- name: Flag for errors (check mode only)
85+
ansible.builtin.set_fact:
86+
error_flag: true
87+
when: ansible_check_mode and __organizations_job_async.failed is defined and __organizations_job_async.failed
88+
89+
- name: Managing Controller Organizations | Wait for finish the Organizations management
90+
ansible.builtin.async_status:
91+
jid: "{{ __organizations_job_async_results_item.ansible_job_id }}"
92+
register: __organizations_job_async_result
93+
until: __organizations_job_async_result.finished
94+
retries: "{{ gateway_organizations_async_retries }}"
95+
delay: "{{ gateway_organizations_async_delay }}"
96+
loop: "{{ __organizations_job_async.results }}"
97+
loop_control:
98+
loop_var: __organizations_job_async_results_item
99+
label: "{{ __operation.verb }} Controller Organization {{ __organizations_job_async_results_item.__controller_organizations_item.name }} | Wait for finish the
100+
organization {{ __operation.action }}"
101+
when: not ansible_check_mode and __organizations_job_async_results_item.ansible_job_id is defined
102+
no_log: "{{ gateway_organizations_secure_logging }}"
103+
vars:
104+
__operation: "{{ operation_translate[__organizations_job_async_results_item.__controller_organizations_item.state | default(platform_state) | default('present')] }}"
105+
ansible_async_dir: "{{ aap_configuration_async_dir }}"
46106
...

0 commit comments

Comments
 (0)