Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install nginx from nginx official or distribution package repos #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ Role Variables
The variables that can be passed to this role and a brief description about
them are as follows.

# Install nginx from nginx repos or distribution repos
nginx_install_from_nginx_repos: false

# When installating from nginix repos, install the mainline (true) or
# stable (false) release
nginx_install_mainline_nginx_release: false

# The max clients allowed
nginx_max_clients: 512

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
nginx_install_from_nginx_repos: false
nginx_install_mainline_nginx_release: false

nginx_max_clients: 512

Expand Down
26 changes: 0 additions & 26 deletions files/epel.repo

This file was deleted.

34 changes: 34 additions & 0 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Include Ubuntu-specific variables
include_vars: ubuntu.yml
when: ansible_distribution == 'Ubuntu'

- name: Include Debian-specific variables
include_vars: debian.yml
when: ansible_distribution == 'Debian'

- name: Download nginx signing key
shell: "curl {{ nginx_signing_key_url }} -o /tmp/nginx_signing.key"
when: nginx_install_from_nginx_repos

- name: Import nginx signing key
apt_key:
file: /tmp/nginx_signing.key
state: present
when: nginx_install_from_nginx_repos

- name: Add the nginx project apt repo
apt_repository:
filename: "nginx"
repo: "deb {{ nginx_repo_location }} {{ ansible_distribution_release }} nginx"
state: present
when: nginx_install_from_nginx_repos

- name: Install the nginx packages and dependencies
apt:
name: "{{ item }}"
state: present
update_cache: true
with_items: "{{ nginx_packages }}"
environment: "{{ env }}"

73 changes: 39 additions & 34 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
---

- name: Install the selinux python module
yum: name=libselinux-python state=present
when: ansible_os_family == "RedHat"

- name: Copy the epel packages
copy: src=epel.repo dest=/etc/yum.repos.d/epel_ansible.repo
when: ansible_os_family == "RedHat"

- name: Install the nginx packages
yum: name={{ item }} state=present
with_items: redhat_pkg
when: ansible_os_family == "RedHat"

- name: Install the nginx packages
apt: name={{ item }} state=present update_cache=yes
with_items: ubuntu_pkg
environment: env
when: ansible_os_family == "Debian"
- name: Install repos and packages
include: "{{ ansible_os_family|lower }}.yml"

- name: Create the directories for site specific configurations
file: path=/etc/nginx/{{ item }} state=directory owner=root group=root mode=0755
file:
path: "/etc/nginx/{{ item }}"
state: directory
owner: root
group: root
mode: 0755
with_items:
- "sites-available"
- "sites-enabled"

- name: Copy the nginx configuration file
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify:
- name: Copy the nginx configuration file
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify:
- restart nginx

- name: Copy the nginx default configuration file
template: src=default.conf.j2 dest=/etc/nginx/conf.d/default.conf
- name: Copy the nginx default configuration file
template:
src: default.conf.j2
dest: /etc/nginx/conf.d/default.conf

- name: Copy the nginx default site configuration file
template: src=default.j2 dest=/etc/nginx/sites-available/default
- name: Copy the nginx default site configuration file
template:
src: default.j2
dest: /etc/nginx/sites-available/default

- name: Create the link for site enabled specific configurations
file: path=/etc/nginx/sites-enabled/default state=link src=/etc/nginx/sites-available/default
file:
path: /etc/nginx/sites-enabled/default
state: link
src: /etc/nginx/sites-available/default

- name: Create the configurations for sites
template: src=site.j2 dest=/etc/nginx/sites-available/{{ item['server']['file_name'] }}
with_items: nginx_sites
template:
src: site.j2
dest: "/etc/nginx/sites-available/{{ item['server']['file_name'] }}"
with_items: "{{ nginx_sites }}"
when: nginx_sites|lower != 'none'

- name: Create the links to enable site configurations
file: path=/etc/nginx/sites-enabled/{{ item['server']['file_name'] }} state=link src=/etc/nginx/sites-available/{{ item['server']['file_name'] }}
with_items: nginx_sites
file:
path: "/etc/nginx/sites-enabled/{{ item['server']['file_name'] }}"
state: link
src: "/etc/nginx/sites-available/{{ item['server']['file_name'] }}"
with_items: "{{ nginx_sites }}"
when: nginx_sites|lower != 'none'
notify:
notify:
- reload nginx

- name: start the nginx service
service: name=nginx state=started enabled=yes
service:
name: nginx
state: started
enabled: true

36 changes: 36 additions & 0 deletions tasks/redhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Include CentOS-specific variables
include_vars: centos.yml
when: ansible_distribution == 'CentOS'

- name: Include RHEL-specific variables
include_vars: rhel.yml
when: ansible_distribution == 'Red Hat Enterprise Linux'

- name: Add the nginx Yum repository
yum_repository:
name: nginx
description: nginx release repository
baseurl: "{{ nginx_repo_location }}"
gpgkey: "{{ nginx_signing_key_url }}"
gpgcheck: true
state: present
when: nginx_install_from_nginx_repos

- name: Add CentOS/RHEL 6 EPEL Yum repository
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
state: present
when: nginx_install_from_nginx_repos == false and ansible_distribution_major_version == '6'

- name: Add CentOS/RHEL 7 EPEL Yum repository
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
state: present
when: nginx_install_from_nginx_repos == false and ansible_distribution_major_version == '7'

- name: Install nginx packages and dependencies
yum:
name: "{{ item }}"
state: present
with_items: "{{ nginx_packages }}"
6 changes: 6 additions & 0 deletions vars/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
nginx_packages:
- nginx
- libselinux-python

nginx_repo_location: "http://nginx.org/packages/{% if nginx_install_mainline_nginx_release %}mainline/{% endif %}centos/{{ ansible_distribution_major_version }}/x86_64/"
7 changes: 7 additions & 0 deletions vars/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
nginx_packages:
- python-selinux
- nginx

nginx_repo_location: "http://nginx.org/packages/{% if nginx_install_mainline_nginx_release %}mainline/{% endif %}debian/"

10 changes: 1 addition & 9 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
---

env:
RUNLEVEL: 1

redhat_pkg:
- nginx

ubuntu_pkg:
- python-selinux
- nginx


nginx_signing_key_url: "https://nginx.org/keys/nginx_signing.key"
6 changes: 6 additions & 0 deletions vars/rhel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
nginx_packages:
- nginx
- libselinux-python

nginx_repo_location: "http://nginx.org/packages/{% if nginx_install_mainline_nginx_release %}mainline/{% endif %}rhel/{{ ansible_distribution_major_version }}/x86_64/"
7 changes: 7 additions & 0 deletions vars/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
nginx_packages:
- python-selinux
- nginx

nginx_repo_location: "http://nginx.org/packages/{% if nginx_install_mainline_nginx_release %}mainline/{% endif %}ubuntu/"