initial commit
This commit is contained in:
38
roles/nginx/README.md
Normal file
38
roles/nginx/README.md
Normal file
@@ -0,0 +1,38 @@
|
||||
Role Name
|
||||
=========
|
||||
|
||||
A brief description of the role goes here.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||
|
||||
- hosts: servers
|
||||
roles:
|
||||
- { role: username.rolename, x: 42 }
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
BSD
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
||||
5
roles/nginx/defaults/main.yml
Normal file
5
roles/nginx/defaults/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
# defaults file for roles/nginx
|
||||
nginx_user: www-data
|
||||
nginx_htpasswd_user: admin
|
||||
nginx_template_file: nginx.conf.j2
|
||||
28
roles/nginx/tasks/configure.yml
Normal file
28
roles/nginx/tasks/configure.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
- name: Create .htpasswd file
|
||||
htpasswd:
|
||||
path: "/etc/nginx/{{ location.basic_auth.file }}"
|
||||
name: "{{ location.basic_auth.user | default('admin') }}"
|
||||
password: "{{ location.basic_auth.password }}"
|
||||
state: present
|
||||
create: yes
|
||||
owner: "{{ nginx_user }}"
|
||||
group: "{{ nginx_user }}"
|
||||
mode: 0600
|
||||
loop: "{{ nginx_server.locations }}"
|
||||
loop_control:
|
||||
loop_var: location
|
||||
label: "{{ location.path }}"
|
||||
when: "location.basic_auth is defined"
|
||||
|
||||
notify:
|
||||
- reload nginx
|
||||
|
||||
- name: Copy Nginx config
|
||||
template:
|
||||
src: "{{ nginx_template_file }}"
|
||||
dest: "{{ nginx_config_dir }}/{{ nginx_config_file }}"
|
||||
owner: "{{ nginx_user }}"
|
||||
group: "{{ nginx_user }}"
|
||||
mode: 0644
|
||||
notify:
|
||||
- reload nginx
|
||||
4
roles/nginx/tasks/main.yml
Normal file
4
roles/nginx/tasks/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
- name: Configure Nginx
|
||||
import_tasks: configure.yml
|
||||
tags: nginx
|
||||
38
roles/nginx/templates/nginx.conf.j2
Normal file
38
roles/nginx/templates/nginx.conf.j2
Normal file
@@ -0,0 +1,38 @@
|
||||
{{ ansible_managed | comment }}
|
||||
|
||||
{% if nginx_server.name is defined %}
|
||||
server {
|
||||
listen {{ nginx_server.port }};
|
||||
|
||||
server_name {{ nginx_server.name }};
|
||||
{% endif %}
|
||||
|
||||
{% for location in nginx_server.locations | default([]) %}
|
||||
location {{ location.path }} {
|
||||
{% if location.proxy_pass is defined %}
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
{% endif %}
|
||||
|
||||
{% if location.basic_auth.file is defined %}
|
||||
auth_basic "Authentication required";
|
||||
auth_basic_user_file /etc/nginx/{{ location.basic_auth.file }};
|
||||
{% endif %}
|
||||
|
||||
{% if location.proxy_pass is defined %}
|
||||
proxy_pass http://localhost:{{ location.proxy_pass.port | default('80') }}{{ location.proxy_pass.path }};
|
||||
{% endif %}
|
||||
|
||||
{% if location.return is defined %}
|
||||
return {{ location.return.code }} {{ location.return.url }};
|
||||
{% endif %}
|
||||
}
|
||||
{% endfor %}
|
||||
{% if nginx_server.name is defined %}
|
||||
{% for include_path in nginx_server.includes | default([]) %}
|
||||
include {{ include_path }};
|
||||
{% endfor %}
|
||||
}
|
||||
{% endif %}
|
||||
2
roles/nginx/vars/main.yml
Normal file
2
roles/nginx/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# vars file for roles/nginx
|
||||
Reference in New Issue
Block a user