Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Commit 47b7db3

Browse files
authored
Refactor role to bring it up to par with other NGINX Ansible roles (#19)
1 parent 23a1d89 commit 47b7db3

21 files changed

+240
-237
lines changed

.ansible-lint

-2
This file was deleted.

.github/ISSUE_TEMPLATE/bug_report.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ labels: ''
66
assignees: ''
77
---
88
### Describe the bug
9+
910
A clear and concise description of what the bug is.
1011

1112
### To reproduce
13+
1214
Steps to reproduce the behavior:
15+
1316
1. Deploy NGINX Controller Agent role using playbook.yml
1417
2. View output/logs/configuration on '...'
1518
3. See error
1619

1720
### Expected behavior
21+
1822
A clear and concise description of what you expected to happen.
1923

20-
### Your environment:
21-
- Version of the NGINX Controller Agent role or specific commit
22-
- Version of Ansible
23-
- Version of Jinja2 (if you are using any templating capability)
24-
- Target deployment platform
24+
### Your environment
25+
26+
- Version of the NGINX Controller Agent role or specific commit
27+
- Version of Ansible
28+
- Target deployment platform
2529

2630
### Additional context
31+
2732
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ labels: ''
66
assignees: ''
77
---
88
### Is your feature request related to a problem? Please describe
9+
910
A clear and concise description of what the problem is. Ex. I'm always frustrated when ...
1011

1112
### Describe the solution you'd like
13+
1214
A clear and concise description of what you want to happen.
1315

1416
### Describe alternatives you've considered
17+
1518
A clear and concise description of any alternative solutions or features you've considered.
1619

1720
### Additional context
21+
1822
Add any other context or screenshots about the feature request here.

.github/pull_request_template.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
### Proposed changes
2+
23
Describe the use case and detail of the change. If this PR addresses an issue on GitHub, make sure to include a link to that issue using one of the [supported keywords](https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue) here in this description (not in the title of the PR).
34

45
### Checklist
6+
57
Before creating a PR, run through this checklist and mark each as complete.
68

7-
- [ ] I have read the [CONTRIBUTING](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/CONTRIBUTING.md) document
8-
- [ ] I have added Molecule tests that prove my fix is effective or that my feature works
9-
- [ ] I have checked that any relevant Molecule tests pass after adding my changes
10-
- [ ] I have updated any relevant documentation (`defaults/main/*.yml`, `README.md` and `CHANGELOG.md`)
9+
- [ ] I have read the [CONTRIBUTING](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/CONTRIBUTING.md) document
10+
- [ ] I have added Molecule tests that prove my fix is effective or that my feature works
11+
- [ ] I have checked that any relevant Molecule tests pass after adding my changes
12+
- [ ] I have updated any relevant documentation (`defaults/main/*.yml`, `README.md` and `CHANGELOG.md`)

.github/release-drafter.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ template: |
8888
8989
## Install & Upgrade
9090
91-
* To install the Ansible NGINX Controller Agent role on a fresh environment, run `ansible-galaxy install nginxinc.nginx_controller_agent`.
92-
* To upgrade the Ansible NGINX Controller Agent role to the latest release, run `ansible-galaxy install -f nginxinc.nginx_controller_agent`.
93-
* To install or upgrade to this specific Ansible NGINX Controller Agent role release ($RESOLVED_VERSION), run `ansible-galaxy install -f nginxinc.nginx_controller_agent,v$RESOLVED_VERSION`.
91+
* To install the Ansible NGINX Controller Agent role on a fresh environment, run `ansible-galaxy install nginxinc.nginx_controller_agent`.
92+
* To upgrade the Ansible NGINX Controller Agent role to the latest release, run `ansible-galaxy install -f nginxinc.nginx_controller_agent`.
93+
* To install or upgrade to this specific Ansible NGINX Controller Agent role release ($RESOLVED_VERSION), run `ansible-galaxy install -f nginxinc.nginx_controller_agent,v$RESOLVED_VERSION`.
9494
9595
## Resources
9696
97-
* Functional configuration examples (check `converge.yml` under each `molecule` scenario) -- [github.com/nginxinc/ansible-role-nginx-controller-agent/tree/$RESOLVED_VERSION/molecule](https://github.com/nginxinc/ansible-role-nginx-controller-agent/tree/$RESOLVED_VERSION/molecule).
98-
* Ansible Galaxy repository -- [galaxy.ansible.com/nginxinc/nginx_controller_agent](https://galaxy.ansible.com/nginxinc/nginx_controller_agent).
99-
* NGINX: Better with Ansible demo -- [github.com/alessfg/nginx-ansible-demo](https://github.com/alessfg/nginx-ansible-demo).
97+
* Functional configuration examples (check `converge.yml` under each `molecule` scenario) -- [github.com/nginxinc/ansible_role_nginx_controller_agent/tree/$RESOLVED_VERSION/molecule](https://github.com/nginxinc/ansible_role_nginx_controller_agent/tree/$RESOLVED_VERSION/molecule).
98+
* Ansible Galaxy repository -- [galaxy.ansible.com/nginxinc/nginx_controller_agent](https://galaxy.ansible.com/nginxinc/nginx_controller_agent).
99+
* NGINX: Better with Ansible demo -- [github.com/alessfg/nginx-ansible-demo](https://github.com/alessfg/nginx-ansible-demo).

.github/workflows/molecule.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ jobs:
3838
- name: Run Molecule tests
3939
run: molecule test -s ${{ matrix.scenario }}
4040
env:
41-
PY_COLORS: "1"
42-
ANSIBLE_FORCE_COLOR: "1"
41+
PY_COLORS: 1
42+
ANSIBLE_FORCE_COLOR: 1

CHANGELOG.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
## 0.1.0 (Unreleased)
44

5-
BUG FIXES:
5+
ENHANCEMENTS:
66

7-
Updated Controller agent script download URL for Controller 3.20 and beyond.
7+
* Refactor role to bring it up to par with other NGINX Ansible roles.
8+
* Implement GitHub Actions CI/CD workflow for repo.
9+
* Add Molecule tests for role.
810

9-
ENHANCEMENTS:
11+
BUG FIXES:
1012

11-
* Implement GitHub Actions CI/CD workflow for repo.
12-
* Add Molecule tests for role.
13+
Updated Controller agent script download URL for Controller 3.20 and beyond.

CODE_OF_CONDUCT.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ members of the project's leadership.
6868
## Attribution
6969

7070
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71-
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
71+
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
7272

7373
[homepage]: https://www.contributor-covenant.org
7474

7575
For answers to common questions about this code of conduct, see
76-
https://www.contributor-covenant.org/faq
76+
<https://www.contributor-covenant.org/faq>

CONTRIBUTING.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ The following is a set of guidelines for contributing to the NGINX Controller Ag
1414
* [Git Guidelines](#git-guidelines)
1515
* [Ansible Guidelines](#ansible-guidelines)
1616

17-
[Code of Conduct](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/CODE_OF_CONDUCT.md)
17+
[Code of Conduct](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/CODE_OF_CONDUCT.md)
1818

1919
## Ask a Question
2020

2121
Don't know how something works? Curious if the role can achieve your desired functionality? Please open an Issue on GitHub with the label `question`.
2222

2323
## Getting Started
2424

25-
Follow our [Installation Guide](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/README.md#Installation) to install Ansible and Molecule and get ready to use the NGINX Controller Agent Ansible role.
25+
Follow our [Installation Guide](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/README.md#Installation) to install Ansible and Molecule and get ready to use the NGINX Controller Agent Ansible role.
2626

2727
### Project Structure
2828

2929
* The NGINX Controller Agent Ansible role is written in `yaml` and supports NGINX Controller.
3030
* The project follows the standard [Ansible role directory structure](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html)
31-
* The main code is found in [`tasks/`](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/tasks/).
32-
* Variables can be found in [`defaults/main/`](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/defaults/main/).
33-
* "Constant" variables can be found in [`vars/main.yml`](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/vars/main.yml).
34-
* Configuration templates for NGINX can be found in [`templates/`](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/templates/).
35-
* [Molecule](https://molecule.readthedocs.io/) tests can be found in [`molecule/`](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/molecule/).
36-
* CI/CD is done via GitHub actions using the workflow files found in [`.github/workflows/`](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/.github/workflows/).
31+
* The main code is found in [`tasks/`](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/tasks/).
32+
* Variables can be found in [`defaults/main/`](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/defaults/main/).
33+
* "Constant" variables can be found in [`vars/main.yml`](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/vars/main.yml).
34+
* Configuration templates for NGINX can be found in [`templates/`](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/templates/).
35+
* [Molecule](https://molecule.readthedocs.io/) tests can be found in [`molecule/`](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/molecule/).
36+
* CI/CD is done via GitHub actions using the workflow files found in [`.github/workflows/`](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/.github/workflows/).
3737

3838
## Contributing
3939

@@ -48,7 +48,7 @@ To suggest an enhancement, please create an issue on GitHub with the label `enha
4848
### Open a Pull Request
4949

5050
* Fork the repo, create a branch, implement your changes, add any relevant Molecule tests, submit a PR when your changes are **tested** (using Molecule) and ready for review.
51-
* Fill in [our pull request template](https://github.com/nginxinc/ansible-role-nginx-controller-agent/blob/main/.github/pull_request_template.md).
51+
* Fill in [our pull request template](https://github.com/nginxinc/ansible_role_nginx_controller_agent/blob/main/.github/pull_request_template.md).
5252

5353
Note: if you’d like to implement a new feature, please consider creating a feature request issue first to start a discussion about the feature.
5454

README.md

+102-69
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,144 @@
1-
NGINX Controller Agent
2-
======================
1+
# Ansible NGINX Controller Agent Role
32

4-
This Role installs, configures, and upgrades the NGINX Controller agent alongside an NGINX Plus instance in a machine.
3+
This role installs, configures, and upgrades the NGINX Controller agent alongside an NGINX Plus instance in a machine.
54

6-
Requirements
7-
------------
5+
## Requirements
86

9-
* [NGINX Plus](https://www.nginx.com/products/nginx/)
10-
* [NGINX Controller](https://www.nginx.com/products/nginx-controller/)
7+
### NGINX Controller and NGINX Plus
118

12-
Role Variables
13-
--------------
9+
* [NGINX Plus](https://www.nginx.com/products/nginx/)
10+
* [NGINX Controller](https://www.nginx.com/products/nginx-controller/)
1411

15-
### Required Variables
12+
### Ansible
1613

17-
`nginx_controller_fqdn` - FQDN of the NGINX Controller instance
14+
* This role is developed and tested with [maintained](https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html) versions of Ansible core (above `2.11`).
15+
* You will need to run this role as a root user using Ansible's `become` parameter. Make sure you have set up the appropriate permissions on your target hosts.
16+
* Instructions on how to install Ansible can be found in the [Ansible website](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#upgrading-ansible-from-version-2-9-and-older-to-version-2-10-or-later).
1817

19-
`nginx_controller_api_key` - The API key used to authenticate to NGINX Controller.
18+
### Molecule (Optional)
2019

21-
### Optional Variables
20+
* Molecule is used to test the various functionalities of the role. The recommended version of Molecule to test this role is `3.3`.
21+
* Instructions on how to install Molecule can be found in the [Molecule website](https://molecule.readthedocs.io/en/latest/installation.html). _You will also need to install the Molecule Docker driver._
2222

23-
`nginx_controller_hostname` - The name of the NGINX instance as reflected in NGINX Controller. Must be unique per instance. (currently redundant with nginx_controller_instance_name)
23+
## Installation
2424

25-
`nginx_controller_location` - The location in NGINX Controller this instance will be automatically added to. Otherwise the location will be 'unspecified' in NGINX Controller.
25+
### Ansible Galaxy
2626

27-
`nginx_controller_instance_name` - The name of the instance as reflected in Controller. Must be unique per instance.
27+
Use `ansible-galaxy install nginxinc.nginx_controller_agent` to install the latest stable release of the role on your system. Alternatively, if you have already installed the role, use `ansible-galaxy install -f nginxinc.nginx_controller_agent` to update the role to the latest release.
2828

29-
Dependencies
30-
------------
29+
### Git
3130

32-
Example Playbook
33-
----------------
31+
Use `git clone https://github.com/nginxinc/ansible_role_nginx_controller_agent.git` to pull the latest edge commit of the role from GitHub.
32+
33+
## Platforms
34+
35+
The NGINX Controller agent Ansible role supports all platforms supported by the [NGINX Controller agent](https://docs.nginx.com/nginx-controller/admin-guides/install/nginx-controller-tech-specs/):
36+
37+
```yaml
38+
Amazon:
39+
- 2017.09
40+
Amazon Linux 2:
41+
- any
42+
CentOS:
43+
- 7.4+
44+
Debian:
45+
- stretch (9)
46+
- buster (10)
47+
RHEL:
48+
- 7.4+
49+
Ubuntu:
50+
- bionic (18.04)
51+
- focal (20.04)
52+
```
53+
54+
## Role Variables
55+
56+
| Variable | Default | Description | Required |
57+
| -------- | ------- | ----------- | -------- |
58+
| `nginx_controller_fqdn` | `""` | FQDN of the NGINX Controller instance | Yes |
59+
| `nginx_controller_api_key` | `""` | The API key used to authenticate to NGINX Controller | Yes |
60+
| `nginx_controller_location` | `"unspecified"` | The location in NGINX Controller this instance will be automatically added to | No |
61+
| `nginx_controller_hostname` | `""` | The unique name of the NGINX instance as reflected in NGINX Controller -- currently redundant with `nginx_controller_instance_name` | No |
62+
| `nginx_controller_instance_name` | `""` | The unique name of the NGINX instance as reflected in NGINX Controller -- currently redundant with `nginx_controller_hostname` | No |
63+
64+
## Example Playbook
3465

3566
To use this role you can create a playbook such as the following:
3667

3768
```yaml
3869
---
39-
- hosts: localhost
40-
gather_facts: false
70+
- name: Fetch NGINX Controller API Key
71+
hosts: localhost
4172
connection: local
42-
73+
gather_facts: false
4374
vars:
4475
nginx_controller_user_email: "[email protected]"
4576
nginx_controller_user_password: "mySecurePassword"
4677
nginx_controller_fqdn: "controller.mydomain.com"
4778
nginx_controller_validate_certs: false
48-
4979
tasks:
50-
- include_role:
51-
name: nginxinc.nginx_controller.nginx_controller_generate_token
52-
53-
- name: Get controller api key for agent registration
54-
uri:
55-
url: "https://{{ nginx_controller_fqdn }}/api/v1/platform/global"
56-
method: "GET"
57-
return_content: yes
58-
status_code: 200
59-
validate_certs: false
60-
headers:
61-
Cookie: "{{nginx_controller_auth_token}}"
62-
register: ctrl_globals
63-
64-
- name: Copy api_key to a variable
65-
set_fact:
66-
api_key: "{{ctrl_globals.json.currentStatus.agentSettings.apiKey}}"
67-
68-
- hosts: tag_new_gateway
80+
- name: Fetch NGINX Controller auth token
81+
include_role:
82+
name: nginxinc.nginx_controller_generate_token
83+
84+
- name: Fetch NGINX Controller API Key for the NGINX Controller agent registration
85+
uri:
86+
url: "https://{{ nginx_controller_fqdn }}/api/v1/platform/global"
87+
method: GET
88+
return_content: yes
89+
status_code: 200
90+
validate_certs: false
91+
headers:
92+
Cookie: "{{ nginx_controller_auth_token }}"
93+
register: ctrl_globals
94+
95+
- name: Filter API Key to a variable
96+
set_fact:
97+
api_key: "{{ ctrl_globals.json.currentStatus.agentSettings.apiKey }}"
98+
99+
- name: Install NGINX Controller agent
100+
hosts: tag_new_gateway
69101
remote_user: ubuntu
70102
become: true
71103
become_method: sudo
72-
gather_facts: yes
73-
74104
tasks:
75-
- name: install minimal support for python2 for Agent install script
76-
apt:
77-
name: "{{ packages }}"
78-
state: present
79-
vars:
80-
packages:
81-
- python-minimal
82-
- libxerces-c3.2
83-
84-
- name: install the agent
85-
include_role:
86-
name: nginxinc.nginx_controller.nginx_controller_agent
87-
vars:
88-
nginx_controller_api_key: "{{ hostvars['localhost']['api_key'] }}"
105+
# - name: Install minimal support for python2 for Agent install script
106+
# apt:
107+
# name:
108+
# - python-minimal
109+
# - libxerces-c3.2
110+
111+
- name: Install the NGINX Controller agent
112+
include_role:
113+
name: nginxinc.nginx_controller_agent
114+
vars:
115+
nginx_controller_api_key: "{{ hostvars['localhost']['api_key'] }}"
89116
```
90117

91-
You can then run `ansible-playbook nginx_controller_agent.yaml` to execute the playbook.
118+
## Other NGINX Ansible Collections and Roles
92119

93-
Alternatively, you can also pass/override any variables at run time using the `--extra-vars` or `-e` flag like so `ansible-playbook nginx_controller_agent.yaml -e "[email protected] nginx_controller_user_password=notsecure nginx_controller_fqdn=controller.example.local nginx_controller_validate_certs=false"`
120+
You can find the Ansible NGINX Core collection of roles to install and configure NGINX Open Source, NGINX Plus, and NGINX App Protect [here](https://github.com/nginxinc/ansible-collection-nginx).
94121

95-
You can also pass/override any variables by passing a `yaml` file containing any number of variables like so `ansible-playbook nginx_controller_agent.yaml -e "@nginx_controller_agent_vars.yaml"`
122+
You can find the Ansible NGINX role to install NGINX OSS and NGINX Plus [here](https://github.com/nginxinc/ansible-role-nginx).
96123

97-
License
98-
-------
124+
You can find the Ansible NGINX configuration role to configure NGINX [here](https://github.com/nginxinc/ansible-role-nginx-config).
99125

100-
[Apache License, Version 2.0](./LICENSE)
126+
You can find the Ansible NGINX App Protect role to install and configure NGINX App Protect WAF and NGINX App Protect DoS [here](https://github.com/nginxinc/ansible-role-nginx-app-protect).
101127

102-
Author Information
103-
------------------
128+
You can find the Ansible NGINX Controller collection of roles to install and configure NGINX Controller [here](https://github.com/nginxinc/ansible-collection-nginx_controller).
104129

105-
[Brian Ehlert](https://github.com/brianehlert)
130+
You can find the Ansible NGINX Unit role to install NGINX Unit [here](https://github.com/nginxinc/ansible-role-nginx-unit).
131+
132+
## License
133+
134+
[Apache License, Version 2.0](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/LICENSE)
135+
136+
## Author Information
106137

107138
[Alessandro Fael Garcia](https://github.com/alessfg)
108139

140+
[Brian Ehlert](https://github.com/brianehlert)
141+
109142
[Daniel Edgar](https://github.com/aknot242)
110143

111-
&copy; [NGINX, Inc.](https://www.nginx.com/) 2021
144+
&copy; [F5 Networks, Inc.](https://www.f5.com/) 2020 - 2021

0 commit comments

Comments
 (0)