From 8747b45c5fcafa191db55d23988041f5ddc696d9 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Mon, 4 Mar 2019 01:59:43 -0500 Subject: Add support for alternate configuration directories, Ubuntu, FreeBSD, etc. --- defaults/main.yml | 2 ++ handlers/main.yml | 10 +++++++++- tasks/enable.yml | 14 ++++++++++++++ tasks/install.yml | 15 +++++++++++++++ tasks/main.yml | 23 ++++++++--------------- 5 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 tasks/enable.yml create mode 100644 tasks/install.yml diff --git a/defaults/main.yml b/defaults/main.yml index 7526a9c..8778182 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -11,3 +11,5 @@ nginx_conf_group: adm # RFC 1918 addresses are already included. Inserted directly into # nginx configuration with an `include` nginx_acl_block: "" + +nginx_conf_dir: "/etc/nginx" diff --git a/handlers/main.yml b/handlers/main.yml index 01a6c2e..0b84e35 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,4 +1,12 @@ -- name: Restart Nginx +- name: Restart Nginx runit: name: nginx state: restarted + listen: Restart Nginx + when: ansible_facts['distribution'].lower() == "void" +- name: Restart Nginx + systemd: + name: nginx + state: restarted + listen: Restart Nginx + when: ansible_facts['distribution'].lower() == "ubuntu" diff --git a/tasks/enable.yml b/tasks/enable.yml new file mode 100644 index 0000000..8d9fcd7 --- /dev/null +++ b/tasks/enable.yml @@ -0,0 +1,14 @@ +- name: 'Enable Nginx [Void]' + file: + src: /etc/sv/nginx + dest: /var/service/nginx + owner: root + group: root + state: link + when: ansible_facts['distribution'].lower() == "void" +- name: 'Enable Nginx [Ubuntu]' + systemd: + enabled: yes + daemon_reload: yes + name: nginx + when: ansible_facts['distribution'].lower() == "ubuntu" diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..72787c0 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,15 @@ +- name: 'Install Nginx [Void}' + xbps: + name: nginx + state: present + when: ansible_facts['distribution'].lower() == "void" +- name: 'Install Nginx [Alpine]' + apk: + name: nginx + state: present + when: ansible_facts['distribution'].lower() == "alpine" +- name: 'Install Nginx [Ubuntu]' + apt: + name: nginx + state: present + when: ansible_facts['distribution'].lower() == "ubuntu" diff --git a/tasks/main.yml b/tasks/main.yml index 23a424b..ab06c87 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,15 +1,8 @@ --- -- name: Install Nginx - xbps: - name: nginx - state: present -- name: Enable Nginx - file: - src: /etc/sv/nginx - dest: /var/service/nginx - owner: root - group: root - state: link +- name: Include install tasks + include_tasks: install.yml +- name: Include enable tasks + include_tasks: enable.yml - name: Lock down and setup configuration directories file: path: '{{item}}' @@ -18,8 +11,8 @@ group: "{{nginx_conf_group}}" mode: "{{nginx_conf_dir_mode}}" loop: - - /etc/nginx - - /etc/nginx/conf.d + - "{{nginx_conf_dir}}" + - "{{nginx_conf_dir}}/conf.d" - name: Create Acme Challenge directory file: path: /var/lib/acme-challenge @@ -30,7 +23,7 @@ - name: Install Main 'nginx.conf' template: src: nginx/nginx.conf - dest: /etc/nginx/nginx.conf + dest: "{{nginx_conf_dir}}/nginx.conf" owner: "{{nginx_conf_owner}}" group: "{{nginx_conf_group}}" mode: "{{nginx_conf_file_mode}}" @@ -39,7 +32,7 @@ - name: Install Other Nginx templates template: src: "nginx/{{item}}" - dest: "/etc/nginx/{{item}}" + dest: "{{nginx_conf_dir}}/{{item}}" owner: "{{nginx_conf_owner}}" group: "{{nginx_conf_group}}" mode: "{{nginx_conf_file_mode}}" -- cgit v1.2.3