mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-24 09:03:29 +07:00
Vhost static OK (dirty)
This commit is contained in:
@@ -1,2 +1,35 @@
|
||||
---
|
||||
# tasks file for .
|
||||
|
||||
- name: APT | Install nginx
|
||||
apt: pkg={{ nginx_apt_package }} state=latest update_cache=yes cache_valid_time=3600
|
||||
|
||||
- name: TEMPLATE | Deploy nginx.conf
|
||||
template: src=etc/nginx/nginx.conf.j2 dest=/etc/nginx/nginx.conf validate= "nginx -t"
|
||||
notify: restart nginx
|
||||
|
||||
- name: FILE | Create /etc/nginx/helpers
|
||||
file: dest=/etc/nginx/helpers owner=root mode=0755 state=directory
|
||||
|
||||
- name: FILE | Create /etc/nginx/ssl
|
||||
file: dest=/etc/nginx/ssl owner=root mode=0755 state=directory
|
||||
|
||||
#- name: COMMAND | Creates DH file
|
||||
# command: openssl dhparam -out {{ nginx_dh_path }} {{ nginx_dh_length }}
|
||||
# args:
|
||||
# creates: "{{ nginx_dh_path }}"
|
||||
|
||||
- name: TEMPLATE | Deploy all helpers
|
||||
template: src={{ item }} dest=/etc/nginx/helpers/{{ item | basename | regex_replace('\.j2$','') }}
|
||||
with_fileglob: '../templates/etc/nginx/helpers/*.j2'
|
||||
notify: reload nginx
|
||||
|
||||
- name: INCLUDE | PHP configuration
|
||||
include: php.yml
|
||||
when: nginx_php
|
||||
|
||||
- name: INCLUDE | Vhosts configuration
|
||||
include: vhost.yml
|
||||
|
||||
# TODO:
|
||||
# - Python
|
||||
# - Ruby (SHIT!)
|
||||
|
||||
10
tasks/php.yml
Normal file
10
tasks/php.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
|
||||
- name: INCLUDE_VARS | Include PHP defaults vars from PHP role if unspecified
|
||||
include_vars: ../../php/defaults/main.yml
|
||||
when: php_fpm_socket is undefined
|
||||
|
||||
- name: TEMPLATE | Deploy PHP upstream (UNIX sockets) to Nginx
|
||||
template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf
|
||||
notify: reload nginx
|
||||
|
||||
49
tasks/vhost.yml
Normal file
49
tasks/vhost.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
|
||||
- name: FILE | Create root folders (foreach nginx_vhosts)
|
||||
file: path={{ nginx_root }}/{{ item.name }} state=directory recurse=yes owner=www-data group=www-data mode=0755
|
||||
file: path={{ nginx_root }}/{{ item.name }}/public state=directory recurse=yes owner=www-data group=www-data mode=0755
|
||||
with_items: nginx_vhosts
|
||||
|
||||
- name: TEMPLATE | Create vhosts
|
||||
template: src=etc/nginx/sites-available/{{ item.template }}.j2 dest=/etc/nginx/sites-available/{{ item.name }}
|
||||
with_items: nginx_vhosts
|
||||
notify: reload nginx
|
||||
|
||||
- name: COMMAND | Get sites available
|
||||
command: ls -1 /etc/nginx/sites-available
|
||||
register: old_vhosts
|
||||
changed_when: false
|
||||
ignore_errors: true
|
||||
|
||||
- name: Delete unmanaged vhosts
|
||||
file: path=/etc/nginx/sites-enabled/{{ item }} state=absent
|
||||
file: path=/etc/nginx/sites-available/{{ item }} state=absent
|
||||
with_items: old_vhosts.stdout_lines
|
||||
when: item not in nginx_vhosts|map(attribute='name') and item != 'default'
|
||||
|
||||
#- name: COPY | Add index.html / index.php
|
||||
# copy: src={{ item }} dest={{ nginx_root }}/{{ item.name }}/public/{{ item }} owner=www-data group=www-data mode=0666
|
||||
# with_fileglob: "*"
|
||||
|
||||
- name: FILE | Enable vhosts (symlink to sites-enabled)
|
||||
file: src=/etc/nginx/sites-available/{{ item.name }} dest=/etc/nginx/sites-enabled/{{ item.name }} state=link
|
||||
with_items: nginx_vhosts
|
||||
notify: reload nginx
|
||||
|
||||
- name: FILE | Create ssl dir per vhost (if needed)
|
||||
file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory
|
||||
with_items: nginx_vhosts
|
||||
when: item.ssl.use is defined and item.ssl.use
|
||||
|
||||
# TODO...
|
||||
#- name: COPY | Deploy SSL keys if needed
|
||||
# copy: src=keys/{{ item.name }}/{{ item.name }}.crt dest=/etc/nginx/ssl/{{ item.name }} mode=660
|
||||
# copy: src=keys/{{ item.name }}/{{ item.name }}.key dest=/etc/nginx/ssl/{{ item.name }} mode=660
|
||||
# with_items: nginx_vhosts
|
||||
# when: item.ssl.use and not generatekey
|
||||
|
||||
# TODO:
|
||||
# - deploy defaults files (index.html/index.php) allready in files/
|
||||
# - work with role "ssl_autosign"
|
||||
|
||||
Reference in New Issue
Block a user