Skip to content

Instantly share code, notes, and snippets.

@dkorn
Created October 11, 2017 08:57
Show Gist options
  • Save dkorn/ad508c8ef9bfb65ef92e8cf90061c716 to your computer and use it in GitHub Desktop.
Save dkorn/ad508c8ef9bfb65ef92e8cf90061c716 to your computer and use it in GitHub Desktop.
Ansible Playbook compiling NGINX from sources, to include particular modules
---
- name: Compile NGINX from sources
hosts: webserver
vars:
nginx_version: nginx-1.13.4
nginx_tarball_url: "http://nginx.org/download/{{ nginx_version }}.tar.gz"
nginx_install_dir: "/tmp/{{ nginx_version }}"
nginx_sbin_path: "/usr/sbin/nginx"
nginx_conf_path: "/etc/nginx/nginx.conf"
nginx_custom_modules: "--with-http_auth_request_module"
tasks:
- name: Installing NGINX Dependencies
become: yes
apt:
name: "{{ item }}"
update_cache: yes
with_items:
- libssl-dev
- zlib1g-dev
- libpcre3
- libpcre3-dev
- unzip
- name: Downloading NGINX sources
get_url:
url: "{{ nginx_tarball_url }}"
dest: "/tmp/{{ nginx_version }}.tar.gz"
register: nginx_source
- name: Unpacking NGINX
unarchive:
copy: no
dest: /tmp/
src: "{{ nginx_source.dest }}"
when: nginx_source.changed
register: nginx_source_unpack
- name: Create required Nginx dirs
become: yes
file:
path: /etc/nginx
state: directory
owner: root
mode: 0755
- name: Configuring NGINX source with custom modules
command: "./configure --sbin-path={{ nginx_sbin_path }} --conf-path={{ nginx_conf_path }} {{ nginx_custom_modules }}"
args:
chdir: "{{ nginx_install_dir }}"
when: nginx_source_unpack|changed
register: nginx_configure
- name: Installing NGINX
become: yes
shell: make && make install
args:
chdir: "{{ nginx_install_dir }}"
when: nginx_configure|changed
- name: Creating NGINX conf file
become: yes
template:
src: nginx.conf
dest: "{{ nginx_conf_path }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0644
- name: Installing NGINX init script (service)
become: yes
template:
src: nginx.init
dest: /etc/init.d/nginx
owner: root
group: root
mode: 0755
- name: Starting NGINX
become: yes
service:
name: nginx
state: started
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment