Skip to content

Commit 871ef9b

Browse files
authored
Merge pull request #314 from Tompage1994/dispatcher_role
Add dispatch role
2 parents c509c72 + 010b205 commit 871ef9b

File tree

9 files changed

+252
-23
lines changed

9 files changed

+252
-23
lines changed

changelogs/fragments/dispatch.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
major_changes:
3+
- Adds dispatch role - A role to run all other roles.
4+
...

examples/configure_controller.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,7 @@
3939
- always
4040

4141
roles:
42-
- {role: settings, when: controller_settings is defined, tags: settings}
43-
- {role: organizations, when: controller_organizations is defined, tags: organizations}
44-
- {role: labels, when: controller_labels is defined, tags: labels}
45-
- {role: users, when: controller_user_accounts is defined, tags: users}
46-
- {role: teams, when: controller_teams is defined, tags: teams}
47-
- {role: credential_types, when: controller_credential_types is defined, tags: credential_types}
48-
- {role: credentials, when: controller_credentials is defined, tags: credentials}
49-
- {role: credential_input_sources, when: controller_credential_input_sources is defined, tags: credential_input_sources}
50-
- {role: notification_templates, when: controller_notifications is defined, tags: notification_templates}
51-
- {role: projects, when: controller_projects is defined, tags: projects}
52-
- {role: execution_environments, when: controller_execution_environments is defined, tags: execution_environments}
53-
- {role: applications, when: controller_applications is defined, tags: applications}
54-
- {role: inventories, when: controller_inventories is defined, tags: inventories}
55-
- {role: instance_groups, when: controller_instance_groups is defined, tags: instance_groups}
56-
- {role: project_update, when: controller_projects is defined, tags: projects}
57-
- {role: inventory_sources, when: controller_inventory_sources is defined, tags: inventory_sources}
58-
- {role: inventory_source_update, when: controller_inventory_sources is defined, tags: inventory_sources}
59-
- {role: hosts, when: controller_hosts is defined, tags: hosts}
60-
- {role: groups, when: controller_groups is defined, tags: inventories}
61-
- {role: job_templates, when: controller_templates is defined, tags: job_templates}
62-
- {role: workflow_job_templates, when: controller_workflows is defined, tags: workflow_job_templates}
63-
- {role: schedules, when: controller_schedules is defined, tags: schedules}
64-
- {role: roles, when: controller_roles is defined, tags: roles}
42+
- dispatch # The dispatch role calls all of the other roles.
6543

6644
tasks:
6745

roles/dispatch/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# controller_configuration.projects
2+
## Description
3+
An Ansible Role to run all roles on Ansible Controller.
4+
5+
## Requirements
6+
ansible-galaxy collection install -r tests/collections/requirements.yml to be installed
7+
Currently:
8+
awx.awx
9+
or
10+
ansible.controller
11+
12+
## Variables
13+
Each role has its own variables, for information on those please see each role which this role will call. This role has one key variable `controller_configuration_dispatcher_roles` and its default value is shown below:
14+
15+
```yaml
16+
controller_configuration_dispatcher_roles:
17+
- {role: settings, var: controller_settings, tags: settings}
18+
- {role: organizations, var: controller_organizations, tags: organizations}
19+
- {role: labels, var: controller_labels, tags: labels}
20+
- {role: users, var: controller_user_accounts, tags: users}
21+
- {role: teams, var: controller_teams, tags: teams}
22+
- {role: credential_types, var: controller_credential_types, tags: credential_types}
23+
- {role: credentials, var: controller_credentials, tags: credentials}
24+
- {role: credential_input_sources, var: controller_credential_input_sources, tags: credential_input_sources}
25+
- {role: notification_templates, var: controller_notifications, tags: notification_templates}
26+
- {role: projects, var: controller_projects, tags: projects}
27+
- {role: execution_environments, var: controller_execution_environments, tags: execution_environments}
28+
- {role: applications, var: controller_applications, tags: applications}
29+
- {role: inventories, var: controller_inventories, tags: inventories}
30+
- {role: instance_groups, var: controller_instance_groups, tags: instance_groups}
31+
- {role: project_update, var: controller_projects, tags: projects}
32+
- {role: inventory_sources, var: controller_inventory_sources, tags: inventory_sources}
33+
- {role: inventory_source_update, var: controller_inventory_sources, tags: inventory_sources}
34+
- {role: hosts, var: controller_hosts, tags: hosts}
35+
- {role: groups, var: controller_groups, tags: inventories}
36+
- {role: job_templates, var: controller_templates, tags: job_templates}
37+
- {role: workflow_job_templates, var: controller_workflows, tags: workflow_job_templates}
38+
- {role: schedules, var: controller_schedules, tags: schedules}
39+
- {role: roles, var: controller_roles, tags: roles}
40+
```
41+
42+
Note that each item has three elements:
43+
- `role` which is the name of the role within redhat_cop.controller_configuration
44+
- `var` which is the variable which is used in that role. We use this to prevent the role being called if the variable is not set
45+
- `tags` the tags which are applied to the role so it is possible to apply tags to a playbook using the dispatcher with these tags.
46+
47+
It is possible to redefine this variable with a subset of roles or with different tags. In general we suggest keeping the same structure and perhaps just using a subset.
48+
49+
50+
### Authentication
51+
|Variable Name|Default Value|Required|Description|Example|
52+
|:---:|:---:|:---:|:---:|:---:|
53+
|`controller_state`|"present"|no|The state all objects will take unless overridden by object default|'absent'|
54+
|`controller_hostname`|""|yes|URL to the Ansible Controller Server.|127.0.0.1|
55+
|`controller_validate_certs`|`True`|no|Whether or not to validate the Ansible Controller Server's SSL certificate.||
56+
|`controller_username`|""|yes|Admin User on the Ansible Controller Server.||
57+
|`controller_password`|""|yes|Controller Admin User's password on the Ansible Controller Server. This should be stored in an Ansible Vault at vars/controller-secrets.yml or elsewhere and called from a parent playbook.||
58+
|`controller_oauthtoken`|""|yes|Controller Admin User's token on the Ansible Controller Server. This should be stored in an Ansible Vault at or elsewhere and called from a parent playbook.||
59+
60+
### Secure Logging Variables
61+
The role defaults to False as normally most projects task does not include sensitive information.
62+
Each role the dispatch role calls has a separate variable which can be turned on to enforce secure logging for that role but defaults to the value of controller_configuration_secure_logging if it is not explicitly called. This allows for secure logging to be toggled for the entire suite of configuration roles with a single variable, or for the user to selectively use it. If neither value is set then each role has a default value of true or false depending on the Red Hat COP suggestions.
63+
64+
|Variable Name|Default Value|Required|Description|
65+
|:---:|:---:|:---:|:---:|
66+
|`controller_configuration_secure_logging`|""|no|This variable enables secure logging as well, but is shared across multiple roles, see above.|
67+
68+
### Asynchronous Retry Variables
69+
The following Variables set asynchronous retries for the role.
70+
If neither of the retries or delay or retries are set, they will default to their respective defaults.
71+
This allows for all items to be created, then checked that the task finishes successfully.
72+
This also speeds up the overall role. Each individual role has its own variable which can allow the individual setting of values. See each role for more the variable names.
73+
74+
|Variable Name|Default Value|Required|Description|
75+
|:---:|:---:|:---:|:---:|
76+
|`controller_configuration_async_retries`|30|no|This variable sets the number of retries to attempt for the role globally.|
77+
|`controller_configuration_async_delay`|1|no|This sets the delay between retries for the role globally.|
78+
79+
## Playbook Examples
80+
### Standard Role Usage
81+
```yaml
82+
---
83+
- name: Playbook to configure ansible controller post installation
84+
hosts: localhost
85+
connection: local
86+
# Define following vars here, or in controller_configs/controller_auth.yml
87+
# controller_hostname: ansible-controller-web-svc-test-project.example.com
88+
# controller_username: admin
89+
# controller_password: changeme
90+
pre_tasks:
91+
- name: Include vars from controller_configs directory
92+
include_vars:
93+
dir: ./yaml
94+
ignore_files: [controller_config.yml.template]
95+
extensions: ["yml"]
96+
roles:
97+
- redhat_cop.controller_configuration.dispatch
98+
```
99+
## License
100+
[MIT](LICENSE)
101+
102+
## Author
103+
[Tom Page](https://github.com/Tompage1994)

roles/dispatch/defaults/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
controller_configuration_dispatcher_roles:
3+
- {role: settings, var: controller_settings, tags: settings}
4+
- {role: organizations, var: controller_organizations, tags: organizations}
5+
- {role: labels, var: controller_labels, tags: labels}
6+
- {role: users, var: controller_user_accounts, tags: users}
7+
- {role: teams, var: controller_teams, tags: teams}
8+
- {role: credential_types, var: controller_credential_types, tags: credential_types}
9+
- {role: credentials, var: controller_credentials, tags: credentials}
10+
- {role: credential_input_sources, var: controller_credential_input_sources, tags: credential_input_sources}
11+
- {role: notification_templates, var: controller_notifications, tags: notification_templates}
12+
- {role: projects, var: controller_projects, tags: projects}
13+
- {role: execution_environments, var: controller_execution_environments, tags: execution_environments}
14+
- {role: applications, var: controller_applications, tags: applications}
15+
- {role: inventories, var: controller_inventories, tags: inventories}
16+
- {role: instance_groups, var: controller_instance_groups, tags: instance_groups}
17+
- {role: project_update, var: controller_projects, tags: projects}
18+
- {role: inventory_sources, var: controller_inventory_sources, tags: inventory_sources}
19+
- {role: inventory_source_update, var: controller_inventory_sources, tags: inventory_sources}
20+
- {role: hosts, var: controller_hosts, tags: hosts}
21+
- {role: groups, var: controller_groups, tags: inventories}
22+
- {role: job_templates, var: controller_templates, tags: job_templates}
23+
- {role: workflow_job_templates, var: controller_workflows, tags: workflow_job_templates}
24+
- {role: schedules, var: controller_schedules, tags: schedules}
25+
- {role: roles, var: controller_roles, tags: roles}
26+
...

roles/dispatch/meta/main.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
galaxy_info:
3+
role_name: "dispatch"
4+
author: "Tom Page"
5+
description: "An Ansible Role which launches all of the roles within the controller_configuration Collection."
6+
company: "Red Hat"
7+
8+
# If the issue tracker for your role is not on github, uncomment the
9+
# next line and provide a value
10+
# issue_tracker_url: http://example.com/issue/tracker
11+
license: "MIT"
12+
13+
min_ansible_version: "2.8"
14+
15+
# Optionally specify the branch Galaxy will use when accessing the GitHub
16+
# repo for this role. During role install, if no tags are available,
17+
# Galaxy will use this branch. During import Galaxy will access files on
18+
# this branch. If Travis integration is configured, only notifications for this
19+
# branch will be accepted. Otherwise, in all cases, the repo's default branch
20+
# (usually master) will be used.
21+
# github_branch:
22+
23+
#
24+
# platforms is a list of platforms, and each platform has a name and a list of versions.
25+
#
26+
platforms:
27+
- name: "EL"
28+
versions:
29+
- "all"
30+
31+
galaxy_tags:
32+
- "controller"
33+
- "aap"
34+
- "awx"
35+
- "configuration"
36+
- "dispatch"
37+
38+
collections:
39+
- ansible.controller
40+
- awx.awx
41+
42+
dependencies: []
43+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
44+
# if you add dependencies to this list.
45+
...

roles/dispatch/tasks/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
3+
- name: "Run redhat_cop.controller_configuration.{{ __role.role }} role"
4+
include_role:
5+
name: "{{ __role.role }}"
6+
apply:
7+
tags: "{{ __role.tags }}"
8+
when: hostvars[inventory_hostname][__role.var] is defined
9+
tags: always
10+
loop: "{{ controller_configuration_dispatcher_roles }}"
11+
loop_control:
12+
loop_var: __role
13+
14+
...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
controller_inventories:
3+
- name: test1
4+
description: test inventory
5+
organization: Default
6+
- name: test2
7+
organization: Default
8+
kind: smart
9+
host_filter: "name__icontains=test"
10+
variables: '{"key1":"val1", "key2":"val2"}'
11+
...
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
controller_projects:
3+
- name: Test Project
4+
scm_type: git
5+
scm_url: https://github.com/ansible/tower-example.git
6+
scm_branch: master
7+
scm_clean: true
8+
description: Test Project 1
9+
organization: Satellite
10+
update: true
11+
wait: true
12+
- name: Test Project 2
13+
scm_type: git
14+
scm_url: https://github.com/ansible/tower-example.git
15+
description: Test Project 2
16+
organization: Satellite
17+
wait: true
18+
- name: Test Inventory source project
19+
scm_type: git
20+
scm_url: https://github.com/ansible/ansible-examples.git
21+
description: ansible-examples
22+
organization: Satellite
23+
wait: true
24+
...

roles/dispatch/tests/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
- name: Run dispatch job to Controller
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
vars:
7+
controller_validate_certs: false
8+
controller_hostname: controller.example.com
9+
controller_username: admin
10+
controller_password: changeme
11+
12+
collections:
13+
- awx.awx
14+
15+
pre_tasks:
16+
- name: Include vars from controller_configs directory
17+
include_vars:
18+
dir: ./configs
19+
extensions: ["yml"]
20+
tags: always
21+
22+
roles:
23+
- ../..
24+
...

0 commit comments

Comments
 (0)