From 98974fbf1aa76cb73f9321d7b61909ca06507766 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 11 May 2018 13:31:31 -0700 Subject: [PATCH 1/5] Implement support to select NGINX repository Resolve #32 - Initial options include using the default NGINX packages included in the host system or using the NGINX packages included in the NGINX repository --- README.md | 8 +++++- defaults/main.yml | 6 +++++ tasks/opensource/install-oss.yml | 46 ++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6ad524e..7596411 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,18 @@ This role has multiple variables. The defaults for all these variables are the f # Default is 'opensource'. type: opensource + # Specify source respository for NGINX Open Source. + # Options are 'nginx_repository' or 'os_repository'. + # Default is nginx_repository. + install_from: nginx_repository + # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'. + # Only works if 'install_from' is set to 'nginx_repository'. # Default is mainline. branch: mainline - # Install nginscript, perl, waf (NGINX Plus only), geoip, image-filter, rtmp and/or xslt modules. + # 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 diff --git a/defaults/main.yml b/defaults/main.yml index 10fb067..020fc8c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,8 +4,14 @@ # Default is 'opensource'. type: opensource +# Specify source respository for NGINX Open Source. +# Options are 'nginx_repository' or 'os_repository'. +# Default is nginx_repository. +install_from: nginx_repository + # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'. +# Only works if 'install_from' is set to 'nginx_repository'. # Default is mainline. branch: mainline diff --git a/tasks/opensource/install-oss.yml b/tasks/opensource/install-oss.yml index 1ae3fd6..d19e5a5 100644 --- a/tasks/opensource/install-oss.yml +++ b/tasks/opensource/install-oss.yml @@ -1,26 +1,38 @@ --- -- import_tasks: setup-debian.yml - when: ansible_os_family == "Debian" +- name: "" + block: -- import_tasks: setup-redhat.yml - when: ansible_os_family == "RedHat" + - import_tasks: setup-debian.yml + when: ansible_os_family == "Debian" -- import_tasks: setup-suse.yml - when: ansible_os_family == "Suse" + - import_tasks: setup-redhat.yml + when: ansible_os_family == "RedHat" -- import_tasks: setup-freebsd.yml - when: ansible_os_family == "FreeBSD" + - import_tasks: setup-suse.yml + when: ansible_os_family == "Suse" -- name: "(Install: Debian/Ubuntu/CentOS/RedHat) Install NGINX" + - import_tasks: setup-freebsd.yml + when: ansible_os_family == "FreeBSD" + + - name: "(Install: Debian/Ubuntu/CentOS/RedHat) Install NGINX" + package: + name: nginx + state: present + when: ansible_os_family != "FreeBSD" + notify: "(Handler: All OSs) Start NGINX" + + - name: "(Install: FreeBSD) Install NGINX" + portinstall: + name: nginx + state: present + when: ansible_os_family == "FreeBSD" + notify: "(Handler: All OSs) Start NGINX" + + when: install_from == "nginx_repository" + +- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX" package: name: nginx state: present - when: ansible_os_family != "FreeBSD" - notify: "(Handler: All OSs) Start NGINX" - -- name: "(Install: FreeBSD) Install NGINX" - portinstall: - name: nginx - state: present - when: ansible_os_family == "FreeBSD" + when: install_from == "os_repository" notify: "(Handler: All OSs) Start NGINX" From 4037b195ff4ae5765a79626d9bda6edee5ecbc47 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 11 May 2018 15:12:06 -0700 Subject: [PATCH 2/5] Refactor repository into a variable --- README.md | 15 ++++++++++++++- defaults/main.yml | 15 ++++++++++++++- tasks/opensource/setup-debian.yml | 14 ++------------ tasks/opensource/setup-redhat.yml | 32 ++----------------------------- tasks/opensource/setup-suse.yml | 11 ++--------- 5 files changed, 34 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 7596411..fd11749 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,24 @@ This role has multiple variables. The defaults for all these variables are the f # Default is 'opensource'. type: opensource - # Specify source respository for NGINX Open Source. + # Specify repository origin for NGINX Open Source. # Options are 'nginx_repository' or 'os_repository'. + # Only works if 'type' is set to 'opensource'. # Default is nginx_repository. install_from: nginx_repository + # Specify source repository for NGINX Open Source. + # Only works if 'install_from' is set to 'nginx_repository'. + # Defaults are the official NGINX repositories. + nginx_repository: + debian: + - 'deb https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx' + - 'deb-src https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx' + redhat: + - https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/ + suse: + - https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}sles/12 + # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'. # Only works if 'install_from' is set to 'nginx_repository'. diff --git a/defaults/main.yml b/defaults/main.yml index 020fc8c..c1120ab 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,11 +4,24 @@ # Default is 'opensource'. type: opensource -# Specify source respository for NGINX Open Source. +# Specify repository origin for NGINX Open Source. # Options are 'nginx_repository' or 'os_repository'. +# Only works if 'type' is set to 'opensource'. # Default is nginx_repository. install_from: nginx_repository +# Specify source repository for NGINX Open Source. +# Only works if 'install_from' is set to 'nginx_repository'. +# Defaults are the official NGINX repositories. +nginx_repository: + debian: + - 'deb https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx' + - 'deb-src https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx' + redhat: + - https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/ + suse: + - https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}sles/12 + # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'. # Only works if 'install_from' is set to 'nginx_repository'. diff --git a/tasks/opensource/setup-debian.yml b/tasks/opensource/setup-debian.yml index 8feb1d4..2b90dd3 100644 --- a/tasks/opensource/setup-debian.yml +++ b/tasks/opensource/setup-debian.yml @@ -1,16 +1,6 @@ --- -- name: "(Install: Debian/Ubuntu) Add Mainline NGINX Repository" +- name: "(Install: Debian/Ubuntu) Add NGINX Repository" apt_repository: repo: "{{ item }}" with_items: - - deb https://nginx.org/packages/mainline/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx - - deb-src https://nginx.org/packages/mainline/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx - when: branch == "mainline" - -- name: "(Install: Debian/Ubuntu) Add Stable NGINX Repository" - apt_repository: - repo: "{{ item }}" - with_items: - - deb https://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx - - deb-src https://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx - when: branch == "stable" + - "{{ nginx_repository.debian }}" diff --git a/tasks/opensource/setup-redhat.yml b/tasks/opensource/setup-redhat.yml index abecbd9..6e70aff 100644 --- a/tasks/opensource/setup-redhat.yml +++ b/tasks/opensource/setup-redhat.yml @@ -1,36 +1,8 @@ --- -- name: "(Install: RedHat) Add Mainline NGINX Repository" +- name: "(Install: CentOS/RedHat) Add NGINX Repository" yum_repository: name: nginx - baseurl: https://nginx.org/packages/mainline/rhel/{{ ansible_distribution_major_version|int }}/$basearch/ + baseurl: "{{ nginx_repository.redhat }}" description: NGINX Repository enabled: yes gpgcheck: yes - when: branch == "mainline" and ansible_distribution == "RedHat" - -- name: "(Install: CentOS) Add Mainline NGINX Repository" - yum_repository: - name: nginx - baseurl: https://nginx.org/packages/mainline/centos/{{ ansible_distribution_major_version|int }}/$basearch/ - description: NGINX Repository - enabled: yes - gpgcheck: yes - when: branch == "mainline" and ansible_distribution == "CentOS" - -- name: "(Install: RedHat) Add Stable NGINX Repository" - yum_repository: - name: nginx - baseurl: https://nginx.org/packages/rhel/{{ ansible_distribution_major_version|int }}/$basearch/ - description: NGINX Repository - enabled: yes - gpgcheck: yes - when: branch == "stable" and ansible_distribution == "RedHat" - -- name: "(Install: CentOS) Add Stable NGINX Repository" - yum_repository: - name: nginx - baseurl: https://nginx.org/packages/centos/{{ ansible_distribution_major_version|int }}/$basearch/ - description: NGINX Repository - enabled: yes - gpgcheck: yes - when: branch == "stable" and ansible_distribution == "CentOS" diff --git a/tasks/opensource/setup-suse.yml b/tasks/opensource/setup-suse.yml index 2a1c61c..3e9b3e1 100644 --- a/tasks/opensource/setup-suse.yml +++ b/tasks/opensource/setup-suse.yml @@ -1,12 +1,5 @@ --- -- name: "(Install: SUSE) Add Mainline NGINX Repository" +- name: "(Install: SUSE) Add NGINX Repository" zypper_repository: name: nginx - repo: https://nginx.org/packages/mainline/sles/12 - when: branch == "mainline" - -- name: "(Install: SUSE) Add Stable NGINX Repository" - zypper_repository: - name: nginx - repo: https://nginx.org/packages/sles/12 - when: branch == "stable" + repo: "{{ nginx_repository.suse }}" From 75939983e18c0b1fdf944d18a88a210a511bbde5 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 11 May 2018 15:48:17 -0700 Subject: [PATCH 3/5] Add stable branch test playbook --- tests/playbooks/{nginx-opensource.yml => nginx-basic.yml} | 0 tests/playbooks/nginx-stable.yml | 8 ++++++++ 2 files changed, 8 insertions(+) rename tests/playbooks/{nginx-opensource.yml => nginx-basic.yml} (100%) create mode 100644 tests/playbooks/nginx-stable.yml diff --git a/tests/playbooks/nginx-opensource.yml b/tests/playbooks/nginx-basic.yml similarity index 100% rename from tests/playbooks/nginx-opensource.yml rename to tests/playbooks/nginx-basic.yml diff --git a/tests/playbooks/nginx-stable.yml b/tests/playbooks/nginx-stable.yml new file mode 100644 index 0000000..27ef08c --- /dev/null +++ b/tests/playbooks/nginx-stable.yml @@ -0,0 +1,8 @@ +--- +- hosts: localhost + become: true + remote_user: root + roles: + - ansible-role-nginx + vars: + branch: stable From c1a4eb6a99745e81e741188d43b6847d0ca62149 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 11 May 2018 16:06:53 -0700 Subject: [PATCH 4/5] Fix Travis --- .travis.yml | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c4878b..7838e42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,55 +5,73 @@ services: env: - distribution: centos version: 6 - playbook: opensource - - distribution: centos - version: 6 - playbook: template + playbook: basic - distribution: centos version: 6 playbook: push + - distribution: centos + version: 6 + playbook: stable + - distribution: centos + version: 6 + playbook: template - distribution: centos version: 7 - playbook: opensource + playbook: basic - distribution: centos version: 7 playbook: template + - distribution: centos + version: 7 + playbook: stable - distribution: centos version: 7 playbook: push - distribution: debian version: jessie - playbook: opensource + playbook: basic - distribution: debian version: jessie playbook: template + - distribution: debian + version: jessie + playbook: stable - distribution: debian version: jessie playbook: push - distribution: debian version: stretch - playbook: opensource + playbook: basic - distribution: debian version: stretch playbook: template + - distribution: debian + version: stretch + playbook: stable - distribution: debian version: stretch playbook: push - distribution: ubuntu version: trusty - playbook: opensource + playbook: basic - distribution: ubuntu version: trusty playbook: template + - distribution: ubuntu + version: trusty + playbook: stable - distribution: ubuntu version: trusty playbook: push - distribution: ubuntu version: xenial - playbook: opensource + playbook: basic - distribution: ubuntu version: xenial playbook: template + - distribution: ubuntu + version: xenial + playbook: stable - distribution: ubuntu version: xenial playbook: push From 8e3ca5e5a06a13391fd39ac8c6ff6908b60f1d0b Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 14 May 2018 11:31:46 -0700 Subject: [PATCH 5/5] Use Ansible ternary operator instead of J2 conditionals --- defaults/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index c1120ab..d61463b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,12 +15,12 @@ install_from: nginx_repository # Defaults are the official NGINX repositories. nginx_repository: debian: - - 'deb https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx' - - 'deb-src https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx' + - deb https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx + - deb-src https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx redhat: - - https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/ + - https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/ suse: - - https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}sles/12 + - https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}sles/12 # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'.