Skip to content

Added tasks to permit pushing vhost files from templates #8

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

Open
wants to merge 15 commits into
base: develop
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
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Stouts.nginx
============

[![Build Status](http://img.shields.io/travis/Stouts/Stouts.nginx.svg?style=flat-square)](https://travis-ci.org/Stouts/Stouts.nginx)
[![Galaxy](http://img.shields.io/badge/galaxy-Stouts.nginx-blue.svg?style=flat-square)](https://galaxy.ansible.com/list#/roles/854)
[![Build Status](http://img.shields.io/travis/bpetit/Stouts.nginx.svg?style=flat-square)](https://travis-ci.org/bpetit/Stouts.nginx)

Ansible role which simple manage nginx

Expand Down Expand Up @@ -42,6 +41,10 @@ nginx_servers: # Setup servers (simplest interface, use cfg
# listen 80;
# server_name test.com;
# location / { root /test; index index.html; }
nginx_templatized_vhosts: # Setup vhosts files (one domain name per configuration file)
# by specifying source template path
# Ex: nginx_templatized_vhosts:
# - { "name": "example.com", "template": "templates/my_vhost.j2" }

nginx_auth_file: "{{nginx_dir}}/.htpasswd" # Where stored passwords
nginx_auth_users: [] # Setup users for http authentication
Expand Down Expand Up @@ -79,12 +82,16 @@ Licensed under the MIT License. See the LICENSE file for details.

#### Feedback, bug-reports, requests, ...

Are [welcome](https://github.com/Stouts/Stouts.nginx/issues)!
Are [welcome](https://github.com/bpetit/Stouts.nginx/issues)!

If you wish to express your appreciation for the role, you are welcome to send
a postcard to:
a postcard to the original author:

Kirill Klenov
pos. Severny 8-3
MO, Istra, 143500
Russia

Or, if it is about this fork:

Benoit Petit <[email protected]>
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

nginx_enabled: yes # The role in enabled
nginx_dir: /etc/nginx # Nginx config directory
nginx_sites_available_dir: "{{ nginx_dir }}/sites-available"
nginx_sites_dir: "{{nginx_dir}}/sites-enabled" # Nginx include directory
nginx_default_site: "{{nginx_sites_dir}}/default"
nginx_delete_default_site: no
Expand Down
8 changes: 6 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---

- name: nginx restart
service: name={{nginx_service_name}} state=restarted
service:
name: "{{nginx_service_name}}"
state: restarted

- name: nginx reload
service: name={{nginx_service_name}} state=reloaded
service:
name: "{{nginx_service_name}}"
state: reloaded
11 changes: 7 additions & 4 deletions tasks/install.deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
- include_vars: "{{ansible_distribution}}.yml"

- name: Install dependencies
apt: name=python-pycurl
apt:
name: python-pycurl

- name: Add nginx repository
apt_repository: repo=ppa:nginx/stable
apt_repository:
repo: ppa:nginx/stable
when: nginx_apt_use_ppa_repo and ansible_distribution == "Ubuntu"

- name: Install Dependencies
apt: name={{item}}
with_items: [ nginx, python-passlib ]
apt:
name: "{{ item }}"
with_items: [ nginx, python-passlib ]
12 changes: 9 additions & 3 deletions tasks/install.red.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
---

- name: Ensure libselinux-python is installed
yum: name=libselinux-python
yum:
name: libselinux-python

- name: Setup repo
copy: src=nginx.repo dest=/etc/yum.repos.d/nginx.repo
copy:
src: nginx.repo
dest: /etc/yum.repos.d/nginx.repo

- name: Install Nginx
yum: name={{nginx_yum_pkg}} enablerepo={{nginx_yum_enablerepo or None}} disablerepo={{nginx_yum_disablerepo or None}}
yum:
name: "{{nginx_yum_pkg}}"
enablerepo: "{{nginx_yum_enablerepo or None}}"
disablerepo: "{{nginx_yum_disablerepo or None}}"
55 changes: 47 additions & 8 deletions tasks/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,62 @@
when: ansible_os_family == 'RedHat'

- name: Ensure that Nginx user is exist
user: name={{nginx_user}} system=yes
user:
name: "{{ nginx_user }}"
system: yes

- name: Delete default site
action: file path={{nginx_default_site}} state=absent
file:
path: "{{ nginx_default_site }}"
state: absent
when: nginx_delete_default_site
notify: nginx restart

- name: Encrypt http auth passwords
htpasswd: path={{nginx_auth_file}} name={{item.name}} password={{item.password}}
with_items: "{{nginx_auth_users}}"
htpasswd:
path: "{{ nginx_auth_file }}"
name: "{{ item.name }}"
password: "{{ item.password }}"
with_items: "{{ nginx_auth_users }}"

- name: Ensure the sites available directory exists
file:
name: "{{ nginx_sites_available_dir }}"
state: directory
when: nginx_sites_available_dir is defined

- name: Create vhosts from template
template:
src: "{{ item.template }}"
dest: "{{ nginx_sites_available_dir }}/{{ item.name }}.conf"
with_items:
- "{{ nginx_templatized_vhosts }}"
when: nginx_templatized_vhosts is defined

- name: Ensure the sites directory is exists
file:
name: "{{ nginx_sites_dir }}"
state: directory

- name: Enable vhosts (from templates)
file:
state: link
src: "{{ nginx_sites_available_dir }}/{{ item.name }}.conf"
dest: "{{ nginx_sites_dir }}/{{ item.name }}.conf"
validate: nginx -t
with_items:
- "{{ nginx_templatized_vhosts }}"
when: nginx_templatized_vhosts is defined

- name: Configure nginx
template: src=nginx.conf.j2 dest={{nginx_dir}}/nginx.conf
template:
src: nginx.conf.j2
dest: "{{ nginx_dir }}/nginx.conf"
notify: nginx restart

- name: Ensure the sites directory is exists
file: name={{nginx_sites_dir}} state=directory

- name: Ensure that nginx is started
service: name={{nginx_service_name}} state=started enabled=yes
service:
name: "{{ nginx_service_name }}"
state: started
enabled: yes
2 changes: 2 additions & 0 deletions templates/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ http {
keepalive_timeout {{nginx_keepalive_timeout}};
keepalive_requests {{nginx_keepalive_requests}};

client_max_body_size {{ nginx_client_max_body_size | default('2M') }};

{% if nginx_gzip %}
gzip on;
gzip_disable "msie6";
Expand Down