From ef1294b91c2435206cf0c4bf1d4d9d3ff17ee468 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 10 Sep 2018 16:05:25 -0700 Subject: [PATCH 1/5] Install NGINX Controller agent --- defaults/main.yml | 7 +++++ handlers/main.yml | 5 +++ meta/main.yml | 1 + tasks/controller/install-controller.yml | 42 +++++++++++++++++++++++++ tasks/controller/setup-debian.yml | 5 +++ tasks/controller/setup-redhat.yml | 7 +++++ tasks/main.yml | 9 ++++-- 7 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 tasks/controller/install-controller.yml create mode 100644 tasks/controller/setup-debian.yml create mode 100644 tasks/controller/setup-redhat.yml diff --git a/defaults/main.yml b/defaults/main.yml index d3007e2..6926563 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -49,6 +49,13 @@ modules: amplify_enable: false amplify_key: null +# Install NGINX Controller. +# Use your NGINX Controller API key. +# Default is null. +controller_enable: false +controller_license: null +controller_api_url: null + # Enable NGINX status data. # Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus. # Default is false. diff --git a/handlers/main.yml b/handlers/main.yml index 0d6967a..ae32703 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -21,3 +21,8 @@ name: unitd state: started enabled: yes + +- name: "(Handler: All OSs) Start NGINX Controller Agent" + service: + name: controller-agent + state: started diff --git a/meta/main.yml b/meta/main.yml index b8e7e26..e94a111 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -35,6 +35,7 @@ galaxy_info: galaxy_tags: - nginx - amplify + - controller - oss - plus - web diff --git a/tasks/controller/install-controller.yml b/tasks/controller/install-controller.yml new file mode 100644 index 0000000..6a2f0bf --- /dev/null +++ b/tasks/controller/install-controller.yml @@ -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_license }}" + +- 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_url }}" + +- 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" diff --git a/tasks/controller/setup-debian.yml b/tasks/controller/setup-debian.yml new file mode 100644 index 0000000..c51d2c0 --- /dev/null +++ b/tasks/controller/setup-debian.yml @@ -0,0 +1,5 @@ +--- +- name: "(Install: Debian/Ubuntu) Add NGINX Controller Repository" + apt_repository: + filename: nginx-controller + repo: deb http://packages.nginx.org/controller/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} controller diff --git a/tasks/controller/setup-redhat.yml b/tasks/controller/setup-redhat.yml new file mode 100644 index 0000000..59e696e --- /dev/null +++ b/tasks/controller/setup-redhat.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index f9fd3d8..e0e8b9e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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_license is defined and controller_license and controller_api_url is defined and controller_api_url + - import_tasks: unit/install-unit.yml when: unit_enable From 4b0feeb0cc61b77dda3d8580a02d5d8698321208 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Tue, 11 Sep 2018 11:26:56 -0700 Subject: [PATCH 2/5] Update documentation and controller variables --- README.md | 118 +++++++++++++++++++----- defaults/main.yml | 40 ++++---- meta/main.yml | 12 ++- tasks/controller/install-controller.yml | 4 +- 4 files changed, 124 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 986a39e..ff9c197 100644 --- a/README.md +++ b/README.md @@ -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: @@ -47,7 +47,7 @@ FreeBSD: - 11 ``` -**NGINX Plus:** +**NGINX Plus** ```yaml CentOS: @@ -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: @@ -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: @@ -171,27 +226,32 @@ modules: amplify_enable: false amplify_key: null +# Install NGINX Controller. +# Use your NGINX Controller API key and NGINX Controller API endpoint. +# Requires NGINX Plus. +# 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. @@ -215,12 +275,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 @@ -241,6 +295,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 @@ -253,19 +317,23 @@ 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 + controller_enable: true + controller_api_key: + controller_api_endpoint: https:///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 diff --git a/defaults/main.yml b/defaults/main.yml index 6926563..76f713d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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: @@ -50,11 +60,18 @@ amplify_enable: false amplify_key: null # Install NGINX Controller. -# Use your NGINX Controller API key. +# Use your NGINX Controller API key and NGINX Controller API endpoint. +# Requires NGINX Plus. # Default is null. controller_enable: false -controller_license: null -controller_api_url: null +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. @@ -62,21 +79,12 @@ controller_api_url: null 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. @@ -100,9 +108,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 diff --git a/meta/main.yml b/meta/main.yml index e94a111..072c6eb 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -34,14 +34,18 @@ galaxy_info: galaxy_tags: - nginx - - amplify - - controller + - nginx-oss - oss + - nginx-plus - plus + - nginx-amplify + - amplify + - nginx-controller + - controller + - nginx-unit + - unit - web - server - - unit - development - - web dependencies: [] diff --git a/tasks/controller/install-controller.yml b/tasks/controller/install-controller.yml index 6a2f0bf..0dd4bde 100644 --- a/tasks/controller/install-controller.yml +++ b/tasks/controller/install-controller.yml @@ -26,13 +26,13 @@ lineinfile: dest: /etc/controller-agent/agent.conf regexp: api_key =.* - line: "api_key = {{ controller_license }}" + 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_url }}" + line: "api_url = {{ controller_api_endpoint }}" - name: "(Setup: All OSs) Configure NGINX Controller Agent API Hostname" lineinfile: From 5ff9b63aff8609106e00f2efffbbd6a437ccdb79 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Tue, 11 Sep 2018 12:32:22 -0700 Subject: [PATCH 3/5] Update task name --- tasks/controller/setup-debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/controller/setup-debian.yml b/tasks/controller/setup-debian.yml index c51d2c0..59f5a54 100644 --- a/tasks/controller/setup-debian.yml +++ b/tasks/controller/setup-debian.yml @@ -1,5 +1,5 @@ --- -- name: "(Install: Debian/Ubuntu) Add NGINX Controller Repository" +- 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 From 9eb372612483e92d3d2c59cae191a77eafd28283 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Tue, 11 Sep 2018 13:08:15 -0700 Subject: [PATCH 4/5] Update documentation Add stub status or REST API prerequisite --- README.md | 5 ++++- defaults/main.yml | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff9c197..c5091f2 100644 --- a/README.md +++ b/README.md @@ -222,13 +222,14 @@ 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. +# Requires NGINX Plus and write access to the NGINX Plus REST API. # Default is null. controller_enable: false controller_api_key: null @@ -326,6 +327,8 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a - role: nginxinc.nginx vars: type: plus + rest_api_enable: true + rest_api_write: true controller_enable: true controller_api_key: controller_api_endpoint: https:///1.4 diff --git a/defaults/main.yml b/defaults/main.yml index 76f713d..6c5ae96 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -55,13 +55,14 @@ 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. +# Requires NGINX Plus and write access to the NGINX Plus REST API. # Default is null. controller_enable: false controller_api_key: null From 809b9e3580ff9470ec3a55ff718739ab30f9c40d Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Wed, 12 Sep 2018 12:16:04 -0700 Subject: [PATCH 5/5] Fix variables in main task --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index e0e8b9e..8941d0b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -37,7 +37,7 @@ when: amplify_enable and amplify_key is defined and amplify_key - import_tasks: controller/install-controller.yml - when: controller_enable and controller_license is defined and controller_license and controller_api_url is defined and controller_api_url + 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