Skip to content

Install NGINX Controller agent #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 96 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Use `ansible-galaxy install nginxinc.nginx` to install the role on your system.

It supports all platforms supported by [NGINX Open Source](https://nginx.org/en/linux_packages.html#mainline) and [NGINX Plus](https://www.nginx.com/products/technical-specs/):

**NGINX Open Source:**
**NGINX Open Source**

```yaml
CentOS:
Expand Down Expand Up @@ -47,7 +47,7 @@ FreeBSD:
- 11
```

**NGINX Plus:**
**NGINX Plus**

```yaml
CentOS:
Expand Down Expand Up @@ -84,7 +84,52 @@ FreeBSD:
- 11
```

**NGINX Unit:**
**NGINX Amplify**

```yaml
CentOS:
versions:
- 6
- 7
RedHat:
versions:
- 6
- 7
Debian:
versions:
- jessie
- stretch
Ubuntu:
versions:
- trusty
- xenial
- artful
- bionic
Amazon Linux:
versions:
- 2017.09
```

**NGINX Controller**

```yaml
CentOS:
versions:
- 7
RedHat:
versions:
- 7
Debian:
versions:
- jessie
- stretch
Ubuntu:
versions:
- xenial
- artful
```

**NGINX Unit**

```yaml
CentOS:
Expand Down Expand Up @@ -154,6 +199,16 @@ nginx_repository:
# Default is mainline.
branch: mainline

# Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role.
license:
certificate: license/nginx-repo.crt
key: license/nginx-repo.key

# Delete NGINX Plus license after installation for security purposes.
# Default is true.
delete_license: true

# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules.
# Default is false.
modules:
Expand All @@ -167,31 +222,37 @@ modules:

# Install NGINX Amplify.
# Use your NGINX Amplify API key.
# Requires access to either the NGINX stub status or the NGINX Plus REST API.
# Default is null.
amplify_enable: false
amplify_key: null

# Install NGINX Controller.
# Use your NGINX Controller API key and NGINX Controller API endpoint.
# Requires NGINX Plus and write access to the NGINX Plus REST API.
# Default is null.
controller_enable: false
controller_api_key: null
controller_api_endpoint: null

# Install NGINX Unit and NGINX Unit modules.
# Use a list of supported NGINX Unit modules.
# Default is false.
unit_enable: false
unit_modules: null

# Enable NGINX status data.
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
# Default is false.
status_enable: false

# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
# Requires NGINX Plus.
# Default is false.
rest_api_enable: false
rest_api_write: false
rest_api_dashboard: false

# Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role.
license:
certificate: license/nginx-repo.crt
key: license/nginx-repo.key

# Delete NGINX Plus license after installation for security purposes.
# Default is true.
delete_license: true

# Enable uploading NGINX configuration files to your system.
# Default for uploading files is false.
# Default location of files is the files folder within the NGINX Ansible role.
Expand All @@ -215,12 +276,6 @@ http_template_listen: 80
http_template_server_name: localhost
stream_template_enable: false
stream_template_listen: 12345

# Install NGINX Unit and NGINX Unit modules.
# Use a list of supported NGINX Unit modules.
# Default is false.
unit_enable: false
unit_modules: null
```

Dependencies
Expand All @@ -241,6 +296,16 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
- role: nginxinc.nginx
```

This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a dynamic inventory containing the `nginx` tag.

```yaml
---
- hosts: tag_nginx
remote_user: root
roles:
- role: nginxinc.nginx
```

This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing NGINX Plus.

```yaml
Expand All @@ -253,19 +318,25 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
type: plus
```

This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a dynamic inventory containing the `nginx` tag.
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost to install NGINX Plus and the NGINX Controller agent.

```yml
---
- hosts: tag_nginx
remote_user: root
```yaml
- hosts: localhost
become: true
roles:
- role: nginxinc.nginx
vars:
type: plus
rest_api_enable: true
rest_api_write: true
controller_enable: true
controller_api_key: <API_KEY_HERE>
controller_api_endpoint: https://<FQDN>/1.4
```

This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost to install NGINX Unit and the PHP/Perl NGINX Unit language modules.

```yml
```yaml
---
- hosts: localhost
become: true
Expand Down
42 changes: 26 additions & 16 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ nginx_repository:
# Default is mainline.
branch: mainline

# Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role.
license:
certificate: license/nginx-repo.crt
key: license/nginx-repo.key

# Delete NGINX Plus license after installation for security purposes.
# Default is true.
delete_license: true

# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules.
# Default is false.
modules:
Expand All @@ -45,31 +55,37 @@ modules:

# Install NGINX Amplify.
# Use your NGINX Amplify API key.
# Requires access to either the NGINX stub status or the NGINX Plus REST API.
# Default is null.
amplify_enable: false
amplify_key: null

# Install NGINX Controller.
# Use your NGINX Controller API key and NGINX Controller API endpoint.
# Requires NGINX Plus and write access to the NGINX Plus REST API.
# Default is null.
controller_enable: false
controller_api_key: null
controller_api_endpoint: null

# Install NGINX Unit and NGINX Unit modules.
# Use a list of supported NGINX Unit modules.
# Default is false.
unit_enable: false
unit_modules: null

# Enable NGINX status data.
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
# Default is false.
status_enable: false

# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
# Requires NGINX Plus.
# Default is false.
rest_api_enable: false
rest_api_write: false
rest_api_dashboard: false

# Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role.
license:
certificate: license/nginx-repo.crt
key: license/nginx-repo.key

# Delete NGINX Plus license after installation for security purposes.
# Default is true.
delete_license: true

# Enable uploading NGINX configuration files to your system.
# Default for uploading files is false.
# Default location of files is the files folder within the NGINX Ansible role.
Expand All @@ -93,9 +109,3 @@ http_template_listen: 80
http_template_server_name: localhost
stream_template_enable: false
stream_template_listen: 12345

# Install NGINX Unit and NGINX Unit modules.
# Use a list of supported NGINX Unit modules.
# Default is false.
unit_enable: false
unit_modules: null
5 changes: 5 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@
name: unitd
state: started
enabled: yes

- name: "(Handler: All OSs) Start NGINX Controller Agent"
service:
name: controller-agent
state: started
11 changes: 8 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ galaxy_info:

galaxy_tags:
- nginx
- amplify
- nginx-oss
- oss
- nginx-plus
- plus
- nginx-amplify
- amplify
- nginx-controller
- controller
- nginx-unit
- unit
- web
- server
- unit
- development
- web

dependencies: []
42 changes: 42 additions & 0 deletions tasks/controller/install-controller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- import_tasks: setup-debian.yml
when: ansible_os_family == "Debian"

- import_tasks: setup-redhat.yml
when: ansible_os_family == "RedHat"

- name: "(Install: All OSs) Install NGINX Controller Agent"
package:
name: nginx-controller-agent
state: present

- name: "(Setup: All OSs) Copy NGINX Controller Agent Configuration Template"
copy:
remote_src: yes
src: /etc/controller-agent/agent.controller.conf.default
dest: /etc/controller-agent/agent.conf

- name: "(Setup: All OSs) Copy NGINX Configurator Agent Configuration Template"
copy:
remote_src: yes
src: /etc/controller-agent/agent.configurator.conf.default
dest: /etc/controller-agent/agent.configurator.conf

- name: "(Setup: All OSs) Configure NGINX Controller Agent API Key"
lineinfile:
dest: /etc/controller-agent/agent.conf
regexp: api_key =.*
line: "api_key = {{ controller_api_key }}"

- name: "(Setup: All OSs) Configure NGINX Controller Agent API URL"
lineinfile:
dest: /etc/controller-agent/agent.conf
regexp: api_url =.*
line: "api_url = {{ controller_api_endpoint }}"

- name: "(Setup: All OSs) Configure NGINX Controller Agent API Hostname"
lineinfile:
dest: /etc/controller-agent/agent.conf
regexp: hostname =.*
line: "hostname = {{ ansible_hostname }}"
notify: "(Handler: All OSs) Start NGINX Controller Agent"
5 changes: 5 additions & 0 deletions tasks/controller/setup-debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: "(Install: Debian/Ubuntu) Add NGINX Controller Agent Repository"
apt_repository:
filename: nginx-controller
repo: deb http://packages.nginx.org/controller/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} controller
7 changes: 7 additions & 0 deletions tasks/controller/setup-redhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: "(Install: CentOS/RedHat) Add NGINX Controller Agent Repository"
yum_repository:
name: nginx-controller
baseurl: http://packages.nginx.org/controller/centos/$releasever/$basearch/
description: NGINX Controller Agent
gpgcheck: yes
9 changes: 6 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
- import_tasks: conf/setup-rest-api.yml
when: rest_api_enable and type == "plus"

- import_tasks: amplify/install-amplify.yml
when: amplify_enable and amplify_key is defined and amplify_key

when: nginx_enable

- import_tasks: amplify/install-amplify.yml
when: amplify_enable and amplify_key is defined and amplify_key

- import_tasks: controller/install-controller.yml
when: controller_enable and controller_api_key is defined and controller_api_key and controller_api_endpoint is defined and controller_api_endpoint

- import_tasks: unit/install-unit.yml
when: unit_enable