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

435 lines
12 KiB
YAML
Raw Normal View History

---
- name: "(Install: Linux) Check For Build Tools"
block:
- name: "(Install: Centos/RHEL) Setup Python 3"
block:
- name: "(Install: Centos/RHEL) Install Python 3"
yum:
name:
- python3
- python3-pip
- python3-devel
update_cache: yes
- name: "(Install: Centos/RHEL) Set Python 3 Default"
alternatives:
name: python
path: /usr/bin/python3
link: /usr/bin/python
when:
- ansible_os_family == "RedHat"
- ansible_distribution_major_version == "8"
- name: "(Install: Centos/RHEL) Install Build Tools"
yum:
name:
- "@Development tools"
- gcc
- glibc
- glibc-common
- gd
- gd-devel
- perl-core
- wget
- ca-certificates
- zlib-devel
2020-07-30 12:47:08 +02:00
update_cache: yes
when: ansible_os_family == "RedHat"
- name: "(Install: Debian) Install Backports Repo For Buster"
apt_repository:
filename: buster-backports
repo: deb http://ftp.us.debian.org/debian buster-backports main
update_cache: yes
mode: 0644
when: ansible_distribution_release == "buster"
- name: "(Install: Debian/Ubuntu) Install Build Tools"
apt:
name:
2020-06-08 15:46:01 +02:00
- python3-minimal
- build-essential
- perl
- tar
- checkinstall
- zlib1g-dev
- libtemplate-perl
2020-07-30 12:47:08 +02:00
update_cache: yes
when: ansible_os_family == "Debian"
- name: "(Install: Alpine) Install Build Tools"
apk:
name:
- python3
- alpine-sdk
- build-base
- git
- wget
- perl
- linux-headers
- tar
- openrc
2020-07-30 12:47:08 +02:00
update_cache: yes
when: ansible_os_family == "Alpine"
- name: "(Install: Alpine) Enable OpenRC"
copy:
content: ""
dest: /run/openrc/softlevel
force: no
owner: root
mode: 0644
when: ansible_os_family == "Alpine"
when: nginx_install_source_build_tools | bool
- name: "(Install: Linux) Check For Source Installs"
block:
- name: "(Install: Linux) Check For PCRE Install"
stat:
path: /tmp/{{ pcre_version }}
register: pcre_result
- name: "(Install: Linux) Check For ZLib Install"
stat:
path: /tmp/{{ zlib_version }}
register: zlib_result
- name: "(Install: Linux) Check For OpenSSL Install"
stat:
path: /tmp/{{ openssl_version }}
register: openssl_result
- name: "(Install: Centos/RHEL) Install PCRE Dependency From Package"
yum:
name: pcre-devel
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_pcre | bool
- ansible_os_family == "RedHat"
- name: "(Install: Debian/Ubuntu) Install PCRE Dependency From Package"
apt:
name: libpcre3-dev
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_pcre | bool
- ansible_os_family == "Debian"
- name: "(Install: Alpine) Install PCRE Dependency From Package"
apk:
name: pcre-dev
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_pcre | bool
- ansible_os_family == "Alpine"
- name: "(Install: Linux) Install PCRE Dependence From Source"
block:
- name: "(Install: Linux) Download PCRE Dependency"
get_url:
url: "http://ftp.pcre.org/pub/pcre/{{ pcre_version }}.tar.gz"
dest: "/tmp/{{ pcre_version }}.tar.gz"
mode: 0600
register: pcre_source
- name: "(Install: Linux) Unpack PCRE Dependency"
unarchive:
copy: no
dest: /tmp/
src: "{{ pcre_source.dest }}"
mode: 0700
- name: "(Install: Linux) Configure PCRE Dependency"
command: "./configure"
args:
chdir: "/tmp/{{ pcre_version }}"
- name: "(Install: Linux) Make PCRE Dependency"
make:
chdir: "/tmp/{{ pcre_version }}"
- name: "(Install: Linux) Install PCRE Dependency"
make:
chdir: "/tmp/{{ pcre_version }}"
target: install
when:
- not pcre_result.stat.exists | bool
- not nginx_install_source_pcre | bool
- name: "(Install: Centos/RHEL) Install ZLib Dependency From Package"
yum:
name: zlib-devel
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_zlib | bool
- ansible_os_family == "RedHat"
- name: "(Install: Debian/Ubuntu) Install ZLib Dependency From Package"
apt:
name: zlib1g-dev
update_cache: true
when:
- nginx_install_source_zlib | bool
- ansible_os_family == "Debian"
- name: "(Install: Alpine) Install ZLib Dependency From Package"
apk:
name: zlib-dev
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_zlib | bool
- ansible_os_family == "Alpine"
- name: "(Install: Linux) Install ZLib Dependency From Source"
block:
- name: "(Install: Linux) Download ZLib Dependency"
get_url:
url: "http://zlib.net/{{ zlib_version }}.tar.gz"
dest: "/tmp/{{ zlib_version }}.tar.gz"
mode: 0600
register: zlib_source
- name: "(Install: Linux) Unpack ZLib Dependency"
unarchive:
copy: no
dest: /tmp/
src: "{{ zlib_source.dest }}"
mode: 0700
- name: "(Install: Linux) Configure zlib Dependency"
command: "./configure"
args:
chdir: "/tmp/{{ zlib_version }}"
- name: "(Install: Linux) Make ZLib Dependency"
make:
chdir: "/tmp/{{ zlib_version }}"
- name: "(Install: Linux) Install ZLib Dependency"
make:
chdir: "/tmp/{{ zlib_version }}"
target: install
when:
- not zlib_result.stat.exists | bool
- not nginx_install_source_zlib | bool
- name: "(Install: Centos/RHEL) Install OpenSSL Dependency From Package"
yum:
name: openssl-devel
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_openssl | bool
- ansible_os_family == "RedHat"
- name: "(Install: Debian/Ubuntu) Install OpenSSL Dependency From Package"
apt:
name: libssl-dev
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_openssl | bool
- ansible_os_family == "Debian"
- name: "(Install: Alpine) Install OpenSSL Dependency From Package"
apk:
name: openssl-dev
2020-07-30 12:47:08 +02:00
update_cache: yes
when:
- nginx_install_source_openssl | bool
- ansible_os_family == "Alpine"
- name: "(Install: Linux) Install OpenSSL Dependency From Source"
block:
- name: "(Install: Linux) Download OpenSSL Dependency"
get_url:
url: "http://www.openssl.org/source/{{ openssl_version }}.tar.gz"
dest: "/tmp/{{ openssl_version }}.tar.gz"
mode: 0600
register: openssl_source
- name: "(Install: Linux) Unpack OpenSSL Dependency"
unarchive:
copy: no
dest: /tmp/
src: "{{ openssl_source.dest }}"
mode: 0700
- name: "(Install: Linux) Configure OpenSSL Dependency"
command: "./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib"
args:
chdir: "/tmp/{{ openssl_version }}"
- name: "(Install: Linux) Make OpenSSL Dependency"
make:
chdir: "/tmp/{{ openssl_version }}"
- name: "(Install: Linux) Install OpenSSL Dependency"
make:
chdir: "/tmp/{{ openssl_version }}"
target: install
when:
- not openssl_result.stat.exists | bool
- not nginx_install_source_openssl | bool
- name: "(Install: Linux) Get NGINX Version"
block:
- name: "(Install: Linux) Fetch NGINX Version"
uri:
url: https://trac.nginx.org/nginx/browser
2020-07-30 12:47:08 +02:00
return_content: yes
register: nginx_versions
- name: "(Install: Linux) Set NGINX Mainline Version"
set_fact:
nginx_version: "{{ nginx_versions.content | regex_search('release[^<]*') | regex_replace('release', 'nginx') }}"
when: nginx_branch == "mainline"
- name: "(Install: Linux) Set NGINX Stable Version 1/2"
set_fact:
nginx_version: "{{ nginx_versions.content | regex_search('stable[^<]*') | regex_replace('stable', 'release') }}"
when: nginx_branch == "stable"
- name: "(Install: Linux) Set NGINX Stable Version 2/2"
set_fact:
nginx_version: "{{ nginx_versions.content | regex_search(nginx_version + '[^<]*') | regex_replace('release', 'nginx') }}"
when: nginx_branch == "stable"
- name: "(Install: Linux) Set NGINX Download Filename"
set_fact:
nginx_download_name: "{{ nginx_version }}"
- name: "(Install: Linux) Check For NGINX Install"
stat:
path: /usr/sbin/nginx
2020-07-30 12:47:08 +02:00
follow: yes
register: nginx_result
- name: "(Install: Linux) Add NGINX User"
user:
name: nginx
- name: "(Install: Linux) Install NGINX"
block:
- name: "(Install: Linux) Download NGINX"
get_url:
url: "http://nginx.org/download/{{ nginx_download_name }}.tar.gz"
dest: "/tmp/{{ nginx_download_name }}.tar.gz"
mode: 0600
register: nginx_source
- name: "(Install: Linux) Unpack NGINX"
unarchive:
copy: no
dest: /tmp/
src: "{{ nginx_source.dest }}"
mode: 0755
- name: "(Install: Linux) Configure NGINX"
command: >-
./configure
--prefix=/usr
--pid-path=/var/run/nginx.pid
--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
--with-http_ssl_module
--with-stream
--with-mail=dynamic
{{ 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
- name: "(Install: Linux) Make NGINX"
make:
chdir: "/tmp/{{ nginx_version }}"
- name: "(Install: Linux) Install NGINX"
make:
chdir: "/tmp/{{ nginx_version }}"
target: install
- name: "(Install: Linux) Upload systemd NGINX Service File"
copy:
src: services/nginx.systemd
dest: /lib/systemd/system/nginx.service
owner: root
group: root
mode: 0644
when: ansible_service_mgr == "systemd"
- name: "(Install: Linux) Enable systemd NGINX Service File"
systemd:
daemon_reload: yes
name: nginx
state: restarted
enabled: yes
when: ansible_service_mgr == "systemd"
notify: "(Handler: All OSs) Start NGINX"
- name: "(Install: Linux) Upload upstart NGINX Service File"
copy:
src: services/nginx.upstart
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
when: ansible_service_mgr == "upstart"
- name: "(Install: Linux) Upload upstart NGINX Service Conf File"
copy:
src: services/nginx.conf.upstart
dest: /etc/init/nginx.conf
owner: root
group: root
mode: 0644
when: ansible_service_mgr == "upstart"
- name: "(Install: Linux) Enable upstart NGINX Service Reload"
command: "initctl reload-configuration"
when: ansible_service_mgr == "upstart"
- name: "(Install: Linux) Start upstart NGINX Service Reload"
command: "nginx"
when: ansible_service_mgr == "upstart"
notify: "(Handler: All OSs) Start NGINX"
- name: "(Install: Linux) Upload sysvinit NGINX Service File"
copy:
src: services/nginx.sysvinit
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
when: ansible_service_mgr == "sysvinit"
notify: "(Handler: All OSs) Start NGINX"
- name: "(Install: Linux) Upload openrc NGINX Service File"
copy:
src: services/nginx.openrc
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
when: ansible_service_mgr == "openrc"
- name: "(Install: Linux) Enable openrc NGINX Service"
command: rc-update add nginx default
notify: "(Handler: All OSs) Start NGINX"
when: ansible_service_mgr == "openrc"
when: not nginx_result.stat.exists
- name: "(Install: Linux) Cleanup Downloads"
file:
path: "{{ item }}"
state: absent
loop:
- "{{ pcre_source.dest }}"
- "{{ zlib_source.dest }}"
- "{{ openssl_source.dest }}"
- "{{ nginx_source.dest }}"
when: item is defined