Skip to content
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
8 changes: 4 additions & 4 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

- name: restart nginx
service:
name=nginx
state=restarted
name: nginx
state: restarted

- name: reload nginx
service:
name=nginx
state=reloaded
name: nginx
state: reloaded
61 changes: 34 additions & 27 deletions tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

- name: common | Create the directories for site specific configurations
file:
path="{{ nginx_etc }}/{{ item }}"
state=directory
owner=root
group=root
mode=0755
path: "{{ nginx_etc }}/{{ item }}"
state: directory
owner: root
group: root
mode: 0755
with_items:
- "sites-available"
- "sites-enabled"
Expand All @@ -15,61 +15,61 @@

- name: common | Copy the nginx default configuration file
template:
src=default.j2
dest="{{ nginx_etc }}/sites-available/default.conf"
src: default.j2
dest: "{{ nginx_etc }}/sites-available/default.conf"

- name: common |Copy the nginx default site configuration file
template:
src=default.j2
dest="{{ nginx_etc }}/sites-available/default"
src: default.j2
dest: "{{ nginx_etc }}/sites-available/default"

- name: common | Create the link for site enabled specific configurations
file:
path="{{ nginx_etc }}/sites-enabled/default"
state=link
src="{{ nginx_etc }}/sites-available/default"
path: "{{ nginx_etc }}/sites-enabled/default"
state: link
src: "{{ nginx_etc }}/sites-available/default"

- name: common | Create the configuration files for nginx
template:
src=site.j2
dest="{{ nginx_etc }}/sites-available/{{ item.file_name }}.conf"
src: site.j2
dest: "{{ nginx_etc }}/sites-available/{{ item.file_name }}.conf"
with_items: "{{ nginx_site }}"
when: nginx_site | lower != 'none'
notify:
- check reload nginx

- name: common | Create the new locations
template:
src=locations.j2
dest="{{ item.nginx_location_file }}"
src: locations.j2
dest: "{{ item.nginx_location_file }}"
with_items: "{{ locations_upstreams_conf | default([]) }}"
notify:
- check reload nginx

- name: common | Create the new upstreams
template:
src=upstreams.j2
dest="{{ item.nginx_upstream_file }}"
src: upstreams.j2
dest: "{{ item.nginx_upstream_file }}"
with_items: "{{ locations_upstreams_conf | default([]) }}"
notify:
- check reload nginx

## TODO: Add condition to disable/enable sites
- name: Create the link for site enabled specific configurations
file:
path="{{ nginx_etc }}/sites-enabled/{{ item.file_name }}.conf"
state=link
src="{{ nginx_etc }}/sites-available/{{ item.file_name }}.conf"
path: "{{ nginx_etc }}/sites-enabled/{{ item.file_name }}.conf"
state: link
src: "{{ nginx_etc }}/sites-available/{{ item.file_name }}.conf"
with_items: "{{ nginx_site }}"
when: nginx_site | lower != 'none'
notify:
- check reload nginx

- name: common | Copy the nginx main configuration file
template:
src=nginx.conf.j2
dest="{{ nginx_etc }}/nginx.conf"
validate='nginx -t -c %s'
src: nginx.conf.j2
dest: "{{ nginx_etc }}/nginx.conf"
validate: 'nginx -t -c %s'
notify:
- check restart nginx

Expand All @@ -78,6 +78,13 @@

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

# systemd module not enabling service if already enabled in sysv
# Workaround https://github.com/ansible/ansible/issues/22303
- name: common | enable the nginx service
service:
name: nginx
enabled: 'yes'
use: service
6 changes: 3 additions & 3 deletions tasks/manage_sites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

- name: manage sites | List of files need to removed
debug:
var=old_files
var: old_files

- name: manage sites | Ensure old services are removed
file:
path="{{ nginx_etc }}/sites-enabled/{{ item.0 }}{{ item.1 }}"
state="absent"
path: "{{ nginx_etc }}/sites-enabled/{{ item.0 }}{{ item.1 }}"
state: "absent"
with_nested:
- "{{ old_files }}"
- [ "", ".conf"]
Expand Down
8 changes: 4 additions & 4 deletions tasks/nginx_debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

- name: nginx_debian | Add the nginx repository
apt_repository:
repo="ppa:nginx/stable"
repo: "ppa:nginx/stable"
when: ansible_os_family == "Debian" and nginx_install_repo == "nginx"
register: nginx_apt_repo

- name: nginx_debian | apt-update nginx
apt:
update_cache=yes
update_cache: yes
when: nginx_apt_repo | changed

- name: nginx_debian | Install the nginx packages
apt:
name="{{ item }}"
state="{{nginx_apt_state}}"
name: "{{ item }}"
state: "{{nginx_apt_state}}"
with_items: "{{ ubuntu_pkg }}"
environment: "{{ env }}"
when: ansible_os_family == "Debian"
16 changes: 8 additions & 8 deletions tasks/nginx_redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

- name: nginx_redhat | Install the selinux python module
yum:
name=libselinux-python
state=present
name: libselinux-python
state: present

- name: nginx_redhat | Check if epel-release exists in yum
command: yum info epel-release
Expand All @@ -12,18 +12,18 @@

- name: nginx_redhat | Copy the epel packages
copy:
src=epel.repo
dest=/etc/yum.repos.d/epel_ansible.repo
src: epel.repo
dest: /etc/yum.repos.d/epel_ansible.repo
when: epel_release_existed.rc != 0

- name: nginx_redhat | Install the epel-release repo
yum:
name=epel-release
state=present
name: epel-release
state: present
when: epel_release_existed.rc == 0

- name: nginx_redhat | Install the nginx packages
yum:
name="{{ item }}"
state=present
name: "{{ item }}"
state: present
with_items: "{{ redhat_pkg }}"
18 changes: 9 additions & 9 deletions tasks/nginx_smartos.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---

- name: nginx_smartos | Set etc nginx
set_fact :
nginx_etc : "/opt/local/etc/nginx"
set_fact:
nginx_etc: "/opt/local/etc/nginx"

- name: nginx_smartos | Install the nginx packages
pkgin:
name="{{ item }}"
state=present
name: "{{ item }}"
state: present
with_items: "{{ solaris_pkg }}"

- name: common | Create the conf.d
file:
path="{{ nginx_etc }}/conf.d"
state=directory
owner=root
group=root
mode=0755
path: "{{ nginx_etc }}/conf.d"
state: directory
owner: root
group: root
mode: 0755
4 changes: 2 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

env:
RUNLEVEL: 1
RUNLEVEL: 1

redhat_pkg:
- python-selinux
Expand All @@ -11,4 +11,4 @@ ubuntu_pkg:
- nginx

solaris_pkg:
- nginx
- nginx