diff --git a/.travis.yml b/.travis.yml index 7838e42..6521269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ env: - distribution: centos version: 6 playbook: template + - distribution: centos + version: 6 + playbook: unit - distribution: centos version: 7 playbook: basic @@ -27,6 +30,9 @@ env: - distribution: centos version: 7 playbook: push + - distribution: centos + version: 7 + playbook: unit - distribution: debian version: jessie playbook: basic @@ -39,6 +45,9 @@ env: - distribution: debian version: jessie playbook: push + - distribution: debian + version: jessie + playbook: unit - distribution: debian version: stretch playbook: basic @@ -51,6 +60,9 @@ env: - distribution: debian version: stretch playbook: push + - distribution: debian + version: stretch + playbook: unit - distribution: ubuntu version: trusty playbook: basic @@ -75,6 +87,39 @@ env: - distribution: ubuntu version: xenial playbook: push + - distribution: ubuntu + version: xenial + playbook: unit + - distribution: ubuntu + version: artful + playbook: basic + - distribution: ubuntu + version: artful + playbook: push + - distribution: ubuntu + version: artful + playbook: stable + - distribution: ubuntu + version: artful + playbook: template + - distribution: ubuntu + version: artful + playbook: unit + - distribution: ubuntu + version: bionic + playbook: basic + - distribution: ubuntu + version: bionic + playbook: push + - distribution: ubuntu + version: bionic + playbook: stable + - distribution: ubuntu + version: bionic + playbook: template + - distribution: ubuntu + version: bionic + playbook: unit before_install: - 'sudo docker pull ${distribution}:${version}' - 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' diff --git a/README.md b/README.md index fd11749..767d12b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Ansible NGINX Role [![Ansible Galaxy](https://img.shields.io/badge/galaxy-nginxinc.nginx-5bbdbf.svg)](https://galaxy.ansible.com/nginxinc/nginx) [![Build Status](https://travis-ci.org/nginxinc/ansible-role-nginx.svg?branch=master)](https://travis-ci.org/nginxinc/ansible-role-nginx) -This role installs NGINX Open Source or NGINX Plus on your target host. +This role installs NGINX Open Source, NGINX Plus, or NGINX Unit on your target host. Requirements ------------ @@ -40,6 +40,41 @@ It supports all platforms supported by [NGINX Open Source](https://nginx.org/en/ **NGINX Plus:** + Debian: + versions: + - jessie + - stretch + Ubuntu: + versions: + - trusty + - xenial + - zesty + - artful + CentOS: + versions: + - 6.5 + - 7 + RedHat: + versions: + - 6.5 + - 7 + Oracle Linux: + versions: + - 6.5 + - 7 + Amazon Linux: + versions: + - 2016.09 + SUSE/SLES: + versions: + - 12 + FreeBSD: + versions: + - 10.3 + - 11 + +**NGINX Unit:** + CentOS: versions: - 6 @@ -50,25 +85,13 @@ It supports all platforms supported by [NGINX Open Source](https://nginx.org/en/ - 7 Debian: versions: - - wheezy - jessie - stretch Ubuntu: versions: - - trusty - xenial - - zesty - SUSE/SLES: - versions: - - 12 - FreeBSD: - versions: - - 10.3 - - 11 - Oracle Linux: - versions: - - 6.5 - - 7 + - artful + - bionic Amazon Linux: versions: - 2016.09 @@ -108,8 +131,12 @@ This role has multiple variables. The defaults for all these variables are the f # Default is mainline. branch: mainline - # Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules. + # Install NGINX Unit and NGINX Unit packages. # Default is false. + unit_enable: false + unit_packages: false + + # Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules. # Default is false. modules: njs: false perl: false @@ -200,6 +227,17 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a roles: - role: nginxinc.nginx +This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost to install NGINX Unit and all NGINX Unit language packages. + + --- + - hosts: localhost + become: true + roles: + - role: nginxinc.nginx + vars: + - unit_enable: true + - unit_packages: true + To run any of the above sample playbooks create a `setup-nginx.yml` file and paste the contents. Executing the Ansible Playbook is then as simple as executing `ansible-playbook setup-nginx.yml`. Alternatively, you can also clone this repository instead of installing it from Ansible Galaxy. If you decide to do so, replace the role variable in the previous sample playbooks from `nginxinc.nginx` to `ansible-role-nginx`. diff --git a/defaults/main.yml b/defaults/main.yml index d61463b..93b0d37 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,6 +28,12 @@ nginx_repository: # Default is mainline. branch: mainline +# Install NGINX Unit and NGINX Unit modules. +# Use a list of supported NGINX Unit modules. +# Default is false. +unit_enable: false +unit_modules: null + # Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules. # Default is false. modules: diff --git a/handlers/main.yml b/handlers/main.yml index 1404c0c..c674128 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -10,3 +10,8 @@ service: name: nginx state: reloaded + +- name: "(Handler: All OSs) Start NGINX Unit" + service: + name: unit + state: started diff --git a/tasks/main.yml b/tasks/main.yml index 0a2ab93..2572896 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -46,3 +46,6 @@ - import_tasks: amplify/install-amplify.yml when: amplify_enable and amplify_key is defined and amplify_key + +- import_tasks: unit/install-unit.yml + when: unit_enable diff --git a/tasks/unit/install-modules.yml b/tasks/unit/install-modules.yml new file mode 100644 index 0000000..fa5fccf --- /dev/null +++ b/tasks/unit/install-modules.yml @@ -0,0 +1,6 @@ +- name: "(Install: All OSs) Install NGINX Unit Modules" + package: + name: "{{ item }}" + state: present + with_items: "{{ unit_modules }}" + notify: "(Handler: All OSs) Start NGINX Unit" diff --git a/tasks/unit/install-unit.yml b/tasks/unit/install-unit.yml new file mode 100644 index 0000000..08dd30c --- /dev/null +++ b/tasks/unit/install-unit.yml @@ -0,0 +1,15 @@ +--- +- 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 Unit" + package: + name: unit + state: present + notify: "(Handler: All OSs) Start NGINX Unit" + +- import_tasks: install-modules.yml + when: unit_modules is defined and unit_modules diff --git a/tasks/unit/setup-debian.yml b/tasks/unit/setup-debian.yml new file mode 100644 index 0000000..8029ab5 --- /dev/null +++ b/tasks/unit/setup-debian.yml @@ -0,0 +1,7 @@ +--- +- name: "(Install: Debian/Ubuntu) Add NGINX Unit Repository" + apt_repository: + repo: "{{ item }}" + with_items: + - deb https://packages.nginx.org/unit/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} unit + - deb-src https://packages.nginx.org/unit/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} unit diff --git a/tasks/unit/setup-redhat.yml b/tasks/unit/setup-redhat.yml new file mode 100644 index 0000000..232c0c9 --- /dev/null +++ b/tasks/unit/setup-redhat.yml @@ -0,0 +1,18 @@ +--- +- name: "(Install: CentOS/RedHat) Add NGINX Unit Repository" + yum_repository: + name: unit + baseurl: https://packages.nginx.org/unit/{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}$releasever/$basearch/ + description: NGINX Unit Repository + enabled: yes + gpgcheck: yes + when: ansible_distribution != "Amazon" + +- name: "(Install: Amazon Linux) Add NGINX Unit Repository" + yum_repository: + name: unit + baseurl: https://packages.nginx.org/unit/amzn/$releasever/$basearch/ + description: NGINX Unit Repository + enabled: yes + gpgcheck: yes + when: ansible_distribution == "Amazon" diff --git a/tests/dockerfiles/Dockerfile.ubuntu-artful b/tests/dockerfiles/Dockerfile.ubuntu-artful new file mode 100644 index 0000000..607907f --- /dev/null +++ b/tests/dockerfiles/Dockerfile.ubuntu-artful @@ -0,0 +1,15 @@ +FROM ubuntu:artful + +RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/* + +RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ + git \ + ansible \ + apt-transport-https \ + curl \ + init \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/sbin/init"] diff --git a/tests/dockerfiles/Dockerfile.ubuntu-bionic b/tests/dockerfiles/Dockerfile.ubuntu-bionic new file mode 100644 index 0000000..bbad82a --- /dev/null +++ b/tests/dockerfiles/Dockerfile.ubuntu-bionic @@ -0,0 +1,15 @@ +FROM ubuntu:bionic + +RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/* + +RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ + git \ + ansible \ + apt-transport-https \ + curl \ + init \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/sbin/init"] diff --git a/tests/playbooks/nginx-unit.yml b/tests/playbooks/nginx-unit.yml new file mode 100644 index 0000000..cd0472e --- /dev/null +++ b/tests/playbooks/nginx-unit.yml @@ -0,0 +1,11 @@ +--- +- hosts: localhost + become: true + remote_user: root + roles: + - ansible-role-nginx + vars: + unit_enable: true + unit_modules: + - unit-php + - unit-perl