Skip to content

Commit 86ba83a

Browse files
author
Jonathan Lozada D
authored
Merge pull request #48 from Tompage1994/license_update
Update license role
2 parents 7310848 + b1a50b3 commit 86ba83a

File tree

9 files changed

+179
-40
lines changed

9 files changed

+179
-40
lines changed

roles/license/README.md

Lines changed: 95 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,109 @@
1-
Role Name
2-
=========
1+
# tower_configuration.license
2+
## Description
3+
An Ansible Role to deploy a license to Ansible Tower.
34

4-
A brief description of the role goes here.
5+
## Requirements
6+
ansible-galaxy collection install -r tests/collections/requirements.yml to be installed
7+
Currently:
8+
awx.awx
59

6-
Requirements
7-
------------
10+
## Variables
11+
|Variable Name|Default Value|Required|Description|Example|
12+
|:---:|:---:|:---:|:---:|:---:|
13+
|`tower_hostname`|""|yes|URL to the Ansible Tower Server.|127.0.0.1|
14+
|`validate_certs`|`False`|no|Whether or not to validate the Ansible Tower Server's SSL certificate.||
15+
|`tower_username`|""|yes|Admin User on the Ansible Tower Server.||
16+
|`tower_password`|""|yes|Tower Admin User's password on the Ansible Tower Server. This should be stored in an Ansible Vault at vars/tower-secrets.yml or elsewhere and called from a parent playbook.||
17+
|`tower_oauthtoken`|""|yes|Tower Admin User's token on the Ansible Tower Server. This should be stored in an Ansible Vault at or elsewhere and called from a parent playbook.||
18+
|`tower_license`|`see below`|yes|Data structure describing your license for Tower, described below.||
819

9-
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
20+
### Secure Logging Variables
21+
The following Variables compliment each other.
22+
If Both variables are not set, secure logging defaults to false.
23+
The role defaults to False as normally the add credential input source task does not include sensative information.
24+
tower_configuration_credential_input_sources_secure_logging defaults to the value of tower_configuration_secure_logging if it is not explicitly called. This allows for secure logging to be toggled for the entire suite of tower configuration roles with a single variable, or for the user to selectively use it.
1025

11-
Role Variables
12-
--------------
26+
|Variable Name|Default Value|Required|Description|
27+
|:---:|:---:|:---:|:---:|
28+
|`tower_configuration_license_secure_logging`|`False`|no|Whether or not to include the sensative license role tasks in the log. Set this value to `True` if you will be providing your sensitive values from elsewhere.|
29+
|`tower_configuration_secure_logging`|`False`|no|This variable enables secure logging as well, but is shared accross multiple roles, see above.|
1330

14-
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
31+
## Data Structure
32+
### Varibles
33+
|Variable Name|Default Value|Required|Type|Description|
34+
|:---:|:---:|:---:|:---:|:---:|
35+
|`data`|""|yes|obj|The contents of the license file (Suggested usage with lookup plugin)|
36+
|`eula_accepted`|""|yes|bool|Whether to accept the End User License Agreement for Ansible Tower|
1537

16-
Dependencies
17-
------------
38+
For further details on fields see https://docs.ansible.com/ansible-tower/latest/html/userguide/credential_plugins.html
1839

19-
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
40+
### Standard Project Data Structure
41+
#### Json Example
42+
```json
43+
---
44+
{
45+
"tower_license": {
46+
"data": "{{ lookup('file', '/tmp/my_tower.license') }}",
47+
"eula_accepted": true
48+
}
49+
}
50+
```
51+
#### Yaml Example
52+
```yaml
53+
---
54+
tower_credential_input_sources:
55+
data: "{{ lookup('file', '/tmp/my_tower.license') }}"
56+
eula_accepted: true
57+
```
2058
21-
Example Playbook
22-
----------------
59+
## Playbook Examples
60+
### Standard Role Usage
61+
```yaml
62+
---
63+
- name: Add License to Tower
64+
hosts: localhost
65+
gather_facts: false
66+
connection: local
2367

24-
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
68+
# Bring in vaulted Ansible Tower secrets
69+
vars_files:
70+
- "../var/tower-secrets.yml"
2571

26-
- hosts: servers
27-
roles:
28-
- { role: username.rolename, x: 42 }
72+
tasks:
2973

30-
License
31-
-------
74+
- name: Get token for use during play
75+
uri:
76+
url: "https://{{ tower_hostname }}/api/v2/tokens/"
77+
method: POST
78+
user: "{{ tower_username }}"
79+
password: "{{ tower_passname }}"
80+
force_basic_auth: true
81+
status_code: 201
82+
validate_certs: false
83+
register: user_token
84+
no_log: true
3285

33-
BSD
86+
- name: Set Tower oath Token
87+
set_fact:
88+
tower_oauthtoken: "{{ user_token.json.token }}"
3489

35-
Author Information
36-
------------------
90+
- name: Import vars
91+
include_vars:
92+
file: "vars/extra_vars.yml"
3793

38-
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
94+
- name: Import JSON
95+
include_vars:
96+
file: "json/license.json"
97+
name: "license_json"
98+
99+
- name: Add License
100+
include_role:
101+
name: redhat_cop.tower_configuration.license
102+
vars:
103+
tower_credential_input_sources: "{{ license_json.tower_license }}"
104+
```
105+
## License
106+
[MIT](LICENSE)
107+
108+
## Author
109+
[Tom Page](https://github.com/Tompage1994)

roles/license/defaults/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
---
2-
# defaults file for license role
2+
tower_hostname: ""
3+
tower_oauthtoken: ""
4+
tower_validate_certs: false
5+
tower_configuration_license_secure_logging: "{{tower_configuration_secure_logging | default(false)}}"
6+
7+
# Example license datastructure but no sensible default.
8+
# tower_license:
9+
# data: "{{ lookup('file', '/tmp/my_tower.license') }}"
10+
# eula_accepted: true

roles/license/meta/main.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ galaxy_info:
3333
versions:
3434
- "all"
3535

36-
galaxy_tags: []
37-
# List tags for your role here, one per line. A tag is a keyword that describes
38-
# and categorizes the role. Users find roles by searching for tags. Be sure to
39-
# remove the '[]' above, if you add tags to this list.
40-
#
41-
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
42-
# Maximum 20 tags per role.
36+
galaxy_tags:
37+
- "ansibletower"
38+
- "tower"
39+
- "awx"
40+
- "configuration"
41+
- "license"
4342

4443
dependencies: []
4544
# List your role dependencies here, one per line. Be sure to remove the '[]' above,

roles/license/tasks/main.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
---
22
# tasks file for license role
3+
- name: Ensure EULA Accepted
4+
assert:
5+
that:
6+
- tower_license.eula_accepted
7+
fail_msg: "You must accept the EULA by passing in the param eula_accepted as true"
8+
39
- name: Install the tower license
410
awx.awx.tower_license:
5-
data: "{{ lookup('file', '/tmp/my_tower.license') }}"
6-
eula_accepted: true
11+
data: "{{ tower_license.data }}"
12+
eula_accepted: "{{ tower_license.eula_accepted }}"
13+
tower_username: "{{ tower_username | default(omit) }}"
14+
tower_password: "{{ tower_password | default(omit) }}"
15+
tower_oauthtoken: "{{ tower_oauthtoken | default(omit) }}"
16+
tower_host: "{{ tower_hostname }}"
17+
tower_config_file: "{{ tower_config_file | default(omit) }}"
18+
validate_certs: "{{ tower_validate_certs | default('true') }}"
19+
no_log: "{{ tower_configuration_license_secure_logging }}"
20+
when: tower_license is defined
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
collections:
3+
- name: awx.awx
4+
version: 13.0.0

roles/license/tests/inventory

Lines changed: 0 additions & 2 deletions
This file was deleted.

roles/license/tests/json/license.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"tower_license": {
3+
"data": "{{ lookup('file', '/tmp/my_tower.license') }}",
4+
"eula_accepted": true
5+
}
6+
}

roles/license/tests/test.yml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
---
2-
- hosts: localhost
3-
remote_user: root
4-
roles:
5-
- license
2+
- name: Add License to Ttower
3+
hosts: localhost
4+
gather_facts: false
5+
connection: local
6+
7+
# Bring in vaulted Ansible Tower secrets
8+
vars_files:
9+
- "../var/tower-secrets.yml"
10+
11+
tasks:
12+
13+
- name: Get token for use during play
14+
uri:
15+
url: "https://{{ tower_hostname }}/api/v2/tokens/"
16+
method: POST
17+
user: "{{ tower_username }}"
18+
password: "{{ tower_passname }}"
19+
force_basic_auth: true
20+
status_code: 201
21+
validate_certs: false
22+
register: user_token
23+
no_log: true
24+
25+
- name: Set Tower oath Token
26+
set_fact:
27+
tower_oauthtoken: "{{ user_token.json.token }}"
28+
29+
- name: Import vars
30+
include_vars:
31+
file: "vars/extra_vars.yml"
32+
33+
- name: Import JSON
34+
include_vars:
35+
file: "json/license.json"
36+
name: "license_json"
37+
38+
- name: Add License
39+
include_role:
40+
name: redhat_cop.tower_configuration.license
41+
vars:
42+
tower_credential_input_sources: "{{ license_json.tower_license }}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Placeholder file
2+
# You should create an Ansible vault here when tower_secrets: true

0 commit comments

Comments
 (0)