ansible-role-nginx/tasks/opensource/install-source.yml

436 lines
12 KiB
YAML
Raw Permalink Normal View History

---
2020-09-19 17:32:17 +02:00
- name: Check for build tools
block:
2020-09-19 17:32:17 +02:00
- name: (CentOS/RHEL 8) Setup Python 3
block:
2020-09-19 17:32:17 +02:00
- name: (CentOS/RHEL 8) Install Python 3
yum:
name:
- python3
- python3-pip
- python3-devel
update_cache: true
2020-09-19 17:32:17 +02:00
- name: (Centos/RHEL 8) Set Python 3 as default
alternatives:
name: python
path: /usr/bin/python3
link: /usr/bin/python
when:
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "RedHat"
- ansible_facts['distribution_major_version'] is version('8', '==')
2020-09-19 17:32:17 +02:00
- name: (Centos/RHEL) Install build tools
yum:
name:
- "@Development tools"
2020-09-15 21:27:06 +02:00
- ca-certificates
- gcc
- gd
- gd-devel
2020-09-15 21:27:06 +02:00
- glibc
- glibc-common
- perl-core
- wget
- zlib-devel
update_cache: true
2020-09-15 21:27:06 +02:00
when: ansible_facts['os_family'] == "RedHat"
2020-09-19 17:32:17 +02:00
- name: (Debian) Install backports repo for 'buster'
apt_repository:
filename: buster-backports
repo: deb http://ftp.us.debian.org/debian buster-backports main
update_cache: true
mode: 0644
2020-09-15 21:27:06 +02:00
when: ansible_facts['distribution_release'] == "buster"
2020-09-19 17:32:17 +02:00
- name: (Debian/Ubuntu) Install build tools
apt:
name:
- build-essential
2020-09-15 21:27:06 +02:00
- checkinstall
- libtemplate-perl
- python3-minimal
- perl
- tar
- zlib1g-dev
update_cache: true
2020-09-15 21:27:06 +02:00
when: ansible_facts['os_family'] == "Debian"
2020-09-19 17:32:17 +02:00
- name: (Alpine Linux) Install build tools
apk:
name:
- alpine-sdk
- build-base
- git
2020-09-15 21:27:06 +02:00
- openrc
- perl
2020-09-15 21:27:06 +02:00
- python3
- linux-headers
- tar
2020-09-15 21:27:06 +02:00
- wget
update_cache: true
2020-09-15 21:27:06 +02:00
when: ansible_facts['os_family'] == "Alpine"
2020-09-19 17:32:17 +02:00
- name: (Alpine Linux) Enable OpenRC
copy:
content: ""
dest: /run/openrc/softlevel
force: false
owner: root
mode: 0644
2020-09-15 21:27:06 +02:00
when: ansible_facts['os_family'] == "Alpine"
when: nginx_install_source_build_tools | bool
2020-09-19 17:32:17 +02:00
- name: Check for source installs
block:
2020-09-19 17:32:17 +02:00
- name: Check for PCRE install
stat:
path: /tmp/{{ pcre_version }}
register: pcre_result
2020-09-19 17:32:17 +02:00
- name: Check for ZLib install
stat:
path: /tmp/{{ zlib_version }}
register: zlib_result
2020-09-19 17:32:17 +02:00
- name: Check for OpenSSL install
stat:
path: /tmp/{{ openssl_version }}
register: openssl_result
2020-09-19 17:32:17 +02:00
- name: (CentOS/RHEL) Install PCRE dependency from package
yum:
name: pcre-devel
update_cache: true
when:
- nginx_install_source_pcre | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "RedHat"
2020-09-19 17:32:17 +02:00
- name: (Debian/Ubuntu) Install PCRE dependency from package
apt:
name: libpcre3-dev
update_cache: true
when:
- nginx_install_source_pcre | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "Debian"
2020-09-19 17:32:17 +02:00
- name: (Alpine Linux) Install PCRE dependency from package
apk:
name: pcre-dev
update_cache: true
when:
- nginx_install_source_pcre | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "Alpine"
2020-09-19 17:32:17 +02:00
- name: Install PCRE dependence from source
block:
2020-09-19 17:32:17 +02:00
- name: Download PCRE dependency
get_url:
2020-09-15 21:27:06 +02:00
url: "https://ftp.pcre.org/pub/pcre/{{ pcre_version }}.tar.gz"
dest: "/tmp/{{ pcre_version }}.tar.gz"
mode: 0600
validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '=='))
| ternary('false', 'true') }}"
register: pcre_source
2020-09-19 17:32:17 +02:00
- name: Unpack PCRE dependency
unarchive:
copy: false
dest: /tmp/
src: "{{ pcre_source.dest }}"
mode: 0700
2020-09-19 17:32:17 +02:00
- name: Configure PCRE dependency
command: ./configure
args:
chdir: "/tmp/{{ pcre_version }}"
2020-09-19 17:32:17 +02:00
- name: Make PCRE dependency
make:
chdir: "/tmp/{{ pcre_version }}"
2020-09-19 17:32:17 +02:00
- name: Install PCRE dependency
make:
chdir: "/tmp/{{ pcre_version }}"
target: install
when:
- not pcre_result.stat.exists | bool
- not nginx_install_source_pcre | bool
- not ansible_check_mode | bool
2020-09-19 17:32:17 +02:00
- name: (Centos/RHEL) Install ZLib dependency from package
yum:
name: zlib-devel
update_cache: true
when:
- nginx_install_source_zlib | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "RedHat"
2020-09-19 17:32:17 +02:00
- name: (Debian/Ubuntu) Install ZLib dependency from package
apt:
name: zlib1g-dev
update_cache: true
when:
- nginx_install_source_zlib | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "Debian"
2020-09-19 17:32:17 +02:00
- name: (Alpine Linux) Install ZLib dependency from package
apk:
name: zlib-dev
update_cache: true
when:
- nginx_install_source_zlib | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "Alpine"
2020-09-19 17:32:17 +02:00
- name: Install ZLib dependency from source
block:
2020-09-19 17:32:17 +02:00
- name: Download ZLib dependency
get_url:
2020-09-15 21:27:06 +02:00
url: "https://zlib.net/{{ zlib_version }}.tar.gz"
dest: "/tmp/{{ zlib_version }}.tar.gz"
mode: 0600
validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '=='))
| ternary('false', 'true') }}"
register: zlib_source
2020-09-19 17:32:17 +02:00
- name: Unpack ZLib dependency
unarchive:
copy: false
dest: /tmp/
src: "{{ zlib_source.dest }}"
mode: 0700
2020-09-19 17:32:17 +02:00
- name: Configure ZLib dependency
command: ./configure
args:
chdir: "/tmp/{{ zlib_version }}"
2020-09-19 17:32:17 +02:00
- name: Make ZLib dependency
make:
chdir: "/tmp/{{ zlib_version }}"
2020-09-19 17:32:17 +02:00
- name: Install ZLib dependency
make:
chdir: "/tmp/{{ zlib_version }}"
target: install
when:
- not zlib_result.stat.exists | bool
- not nginx_install_source_zlib | bool
- not ansible_check_mode | bool
2020-09-19 17:32:17 +02:00
- name: (CentOS/RHEL) Install OpenSSL dependency from package
yum:
name: openssl-devel
update_cache: true
when:
- nginx_install_source_openssl | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "RedHat"
2020-09-19 17:32:17 +02:00
- name: (Debian/Ubuntu) Install OpenSSL dependency from package
apt:
name: libssl-dev
update_cache: true
when:
- nginx_install_source_openssl | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "Debian"
2020-09-19 17:32:17 +02:00
- name: (Alpine Linux) Install OpenSSL dependency from package
apk:
name: openssl-dev
update_cache: true
when:
- nginx_install_source_openssl | bool
2020-09-15 21:27:06 +02:00
- ansible_facts['os_family'] == "Alpine"
2020-09-19 17:32:17 +02:00
- name: Install OpenSSL dependency from source
block:
2020-09-19 17:32:17 +02:00
- name: Download OpenSSL dependency
get_url:
2020-09-15 21:27:06 +02:00
url: "https://www.openssl.org/source/{{ openssl_version }}.tar.gz"
dest: "/tmp/{{ openssl_version }}.tar.gz"
mode: 0600
validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '=='))
| ternary('false', 'true') }}"
register: openssl_source
2020-09-19 17:32:17 +02:00
- name: Unpack OpenSSL dependency
unarchive:
copy: false
dest: /tmp/
src: "{{ openssl_source.dest }}"
mode: 0700
2020-09-19 17:32:17 +02:00
- name: Configure OpenSSL dependency
command: ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib
args:
chdir: "/tmp/{{ openssl_version }}"
2020-09-19 17:32:17 +02:00
- name: Make OpenSSL dependency
make:
chdir: "/tmp/{{ openssl_version }}"
2020-09-19 17:32:17 +02:00
- name: Install OpenSSL dependency
make:
chdir: "/tmp/{{ openssl_version }}"
target: install
when:
- not openssl_result.stat.exists | bool
- not nginx_install_source_openssl | bool
- not ansible_check_mode | bool
2020-09-19 17:32:17 +02:00
- name: Get NGINX version
block:
2020-09-19 17:32:17 +02:00
- name: Fetch NGINX version
uri:
url: https://version.nginx.com/nginx/{{ nginx_branch }}
return_content: true
validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '=='))
| ternary('false', 'true') }}"
check_mode: false
register: nginx_versions
- name: Set NGINX version
set_fact:
nginx_version: "{{ 'nginx-' + (nginx_versions.content | regex_search('([0-9]+\\.){2}[0-9]+')) }}"
2020-09-19 17:32:17 +02:00
- name: Check for NGINX install
stat:
path: /usr/sbin/nginx
follow: true
register: nginx_result
2020-09-19 17:32:17 +02:00
- name: Add NGINX user
user:
name: nginx
2020-09-19 17:32:17 +02:00
- name: Install NGINX
block:
2020-09-19 17:32:17 +02:00
- name: Download NGINX
get_url:
url: "https://nginx.org/download/{{ nginx_version }}.tar.gz"
dest: "/tmp/{{ nginx_version }}.tar.gz"
mode: 0600
validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '=='))
| ternary('false', 'true') }}"
register: nginx_source
2020-09-19 17:32:17 +02:00
- name: Unpack NGINX
unarchive:
copy: false
dest: /tmp/
src: "{{ nginx_source.dest }}"
mode: 0755
2020-09-19 17:32:17 +02:00
- name: Configure NGINX
command: >-
./configure
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--lock-path=/var/lock/nginx.lock
--modules-path=/usr/lib/nginx/modules
2020-09-15 21:27:06 +02:00
--prefix=/usr
--pid-path=/var/run/nginx.pid
--with-http_ssl_module
--with-mail=dynamic
2020-09-15 21:27:06 +02:00
--with-stream
{{ nginx_install_source_pcre | ternary('', '--with-pcre=../' + pcre_version) }}
{{ nginx_install_source_zlib | ternary('', '--with-zlib=../' + zlib_version) }}
{{ nginx_install_source_openssl | ternary('', '--with-openssl=../' + openssl_version) }}
args:
chdir: "/tmp/{{ nginx_version }}"
register: nginx_configure
2020-09-19 17:32:17 +02:00
- name: Make NGINX
make:
chdir: "/tmp/{{ nginx_version }}"
2020-09-19 17:32:17 +02:00
- name: Install NGINX
make:
chdir: "/tmp/{{ nginx_version }}"
target: install
2020-09-19 17:32:17 +02:00
- name: Upload systemd NGINX service file
copy:
src: services/nginx.systemd
dest: /lib/systemd/system/nginx.service
owner: root
group: root
mode: 0644
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "systemd"
2020-09-19 17:32:17 +02:00
- name: Enable systemd NGINX service file
systemd:
daemon_reload: true
name: nginx
state: restarted
enabled: true
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "systemd"
2020-09-17 17:00:27 +02:00
notify: "(Handler) Run NGINX"
2020-09-19 17:32:17 +02:00
- name: Upload upstart NGINX service file
copy:
src: services/nginx.upstart
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "upstart"
2020-09-19 17:32:17 +02:00
- name: Upload Upstart NGINX service conf file
copy:
src: services/nginx.conf.upstart
dest: /etc/init/nginx.conf
owner: root
group: root
mode: 0644
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "upstart"
2020-09-19 17:32:17 +02:00
- name: Enable Upstart NGINX service reload
command: initctl reload-configuration
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "upstart"
2020-09-19 17:32:17 +02:00
- name: Start Upstart NGINX service reload
command: nginx
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "upstart"
2020-09-17 17:00:27 +02:00
notify: "(Handler) Run NGINX"
2020-09-19 17:32:17 +02:00
- name: Upload SysVinit NGINX service file
copy:
src: services/nginx.sysvinit
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "sysvinit"
2020-09-17 17:00:27 +02:00
notify: "(Handler) Run NGINX"
2020-09-19 17:32:17 +02:00
- name: Upload OpenRC NGINX service file
copy:
src: services/nginx.openrc
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "openrc"
2020-09-19 17:32:17 +02:00
- name: Enable OpenRC NGINX service
command: rc-update add nginx default
2020-09-15 21:27:06 +02:00
when: ansible_facts['service_mgr'] == "openrc"
2020-09-19 17:32:17 +02:00
notify: (Handler) Run NGINX
when:
- not nginx_result.stat.exists | bool
- not ansible_check_mode | bool
2020-09-19 17:32:17 +02:00
- name: Cleanup downloads
file:
path: "{{ item }}"
state: absent
loop:
- "{{ pcre_source.dest }}"
- "{{ zlib_source.dest }}"
- "{{ openssl_source.dest }}"
- "{{ nginx_source.dest }}"
when: item is defined