Add new method to install the NGINX Controller agent (#205)

This commit is contained in:
Alessandro Fael Garcia 2019-12-11 18:25:20 -08:00 committed by GitHub
parent 3b6c744166
commit f54b7d2f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 124 additions and 61 deletions

View File

@ -379,7 +379,8 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
nginx_type: plus nginx_type: plus
``` ```
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. 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. Commented out
are sample variables to install the NGINX Controller agent from your NGINX Controller instance instead of the NGINX repository.
```yaml ```yaml
- hosts: localhost - hosts: localhost
@ -392,8 +393,18 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
nginx_rest_api_port: 80 nginx_rest_api_port: 80
nginx_rest_api_write: true nginx_rest_api_write: true
nginx_controller_enable: true nginx_controller_enable: true
nginx_controller_source: repository
nginx_controller_api_key: <API_KEY_HERE> nginx_controller_api_key: <API_KEY_HERE>
nginx_controller_api_endpoint: https://<FQDN>/1.4 nginx_controller_endpoint: <FQDN> # e.g. controller.nginx.com
# nginx_type: plus
# nginx_rest_api_enable: true
# nginx_rest_api_port: 80
# nginx_rest_api_write: true
# nginx_controller_enable: true
# nginx_controller_source: instance
# nginx_controller_endpoint: controller.nginx.com
# nginx_controller_user_email: john_doe@nginx.com
# nginx_controller_password: password
``` ```
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. 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.

View File

@ -1,8 +1,25 @@
--- ---
# Install NGINX Controller. # Install NGINX Controller Agent.
# Use your NGINX Controller API key and NGINX Controller API endpoint.
# Requires NGINX Plus and write access to the NGINX Plus REST API. # Requires NGINX Plus and write access to the NGINX Plus REST API.
# Default is null.
nginx_controller_enable: false nginx_controller_enable: false
# Set the source from where to pull the NGINX Controller Agent.
# Options are 'instance', to pull the NGINX Controller Agent install script
# from your NGINX Controller instance, or 'repository', to pull the NGINX
# Controller Agent from the NGINX repository.
# Default is instance.
nginx_controller_source: instance
# Set your NGINX Controller Endpoint. Required for both types of NGINX Controller
# installation.
nginx_controller_endpoint: null
# Set your NGINX Controller API key.
# Required when 'nginx_controller_source' is set to 'repository'.
# Default is null.
nginx_controller_api_key: null nginx_controller_api_key: null
nginx_controller_api_endpoint: null
# Set your NGINX Controller Admin Email and Password.
# Required when 'nginx_controller_source' is set to 'instance'.
nginx_controller_user_email: null
nginx_controller_password: null

View File

@ -1,42 +1,15 @@
--- ---
- import_tasks: setup-debian.yml - import_tasks: setup-controller-instance.yml
when: ansible_os_family == "Debian" when:
- nginx_controller_source == "instance"
- nginx_controller_user_email is defined
- nginx_controller_user_email | length > 0
- nginx_controller_password is defined
- nginx_controller_password | length > 0
- import_tasks: setup-redhat.yml
when: ansible_os_family == "RedHat"
- name: "(Install: All OSs) Install NGINX Controller Agent" - import_tasks: setup-controller-repository.yml
package: when:
name: nginx-controller-agent - nginx_controller_source == "repository"
state: present - nginx_controller_api_key is defined
- nginx_controller_api_key | length > 0
- 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 = {{ nginx_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 = {{ nginx_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"

View File

@ -0,0 +1,28 @@
---
- name: "(Install: All OSs) Fetch NGINX Controller API Key"
uri:
url: "https://{{ nginx_controller_endpoint }}/sapi/auth/login/"
method: "POST"
body:
email: "{{ nginx_controller_user_email }}"
password: "{{ nginx_controller_password }}"
body_format: json
return_content: yes
status_code: 200
validate_certs: false
register: controller_return
- name: "(Install: All OSs) Download the NGINX Controller Agent Installer Script"
get_url:
url: "https://{{ nginx_controller_endpoint }}:8443/1.4/install/controller/"
dest: /tmp/install.sh
validate_certs: no
force: yes
- name: "(Install: All OSs) Run the NGINX Controller Agent Installer Script"
command: "sh ./install.sh -y"
args:
chdir: /tmp
creates: /var/log/nginx-controller/agent.log
environment:
API_KEY: "{{ controller_return.json.api_key }}"

View File

@ -0,0 +1,48 @@
---
- name: "(Install: Debian/Ubuntu) Add NGINX Controller Agent Repository"
apt_repository:
filename: nginx-controller
repo: deb https://packages.nginx.org/controller/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release | lower }} controller
- name: "(Install: CentOS/RedHat) Add NGINX Controller Agent Repository"
yum_repository:
name: nginx-controller
baseurl: https://packages.nginx.org/controller/centos/$releasever/$basearch/
description: NGINX Controller Agent
gpgcheck: yes
- 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 = {{ nginx_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 = https://{{ nginx_controller_endpoint }}/1.4"
- 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"

View File

@ -1,5 +0,0 @@
---
- 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

View File

@ -1,7 +0,0 @@
---
- 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

View File

@ -85,10 +85,8 @@
- import_tasks: controller/install-controller.yml - import_tasks: controller/install-controller.yml
when: when:
- nginx_controller_enable | bool - nginx_controller_enable | bool
- nginx_controller_api_key is defined - nginx_controller_endpoint is defined
- nginx_controller_api_key | length > 0 - nginx_controller_endpoint | length > 0
- nginx_controller_api_endpoint is defined
- nginx_controller_api_endpoint | length > 0
tags: nginx_install_controller tags: nginx_install_controller
- import_tasks: unit/install-unit.yml - import_tasks: unit/install-unit.yml