task 1-4
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
---
|
||||
# Variable setup.
|
||||
- name: Include OS-specific variables.
|
||||
include_vars: "{{ ansible_facts.os_family }}.yml"
|
||||
|
||||
- name: Define nginx_user.
|
||||
set_fact:
|
||||
nginx_user: "{{ __nginx_user }}"
|
||||
when: nginx_user is not defined
|
||||
|
||||
# Setup/install tasks.
|
||||
- include_tasks: setup-RedHat.yml
|
||||
when: ansible_facts.os_family == 'RedHat' or ansible_facts.os_family == 'Rocky' or ansible_facts.os_family == 'AlmaLinux'
|
||||
|
||||
- include_tasks: setup-Ubuntu.yml
|
||||
when: ansible_facts.distribution == 'Ubuntu'
|
||||
|
||||
- include_tasks: setup-Debian.yml
|
||||
when: ansible_facts.os_family == 'Debian'
|
||||
|
||||
- include_tasks: setup-FreeBSD.yml
|
||||
when: ansible_facts.os_family == 'FreeBSD'
|
||||
|
||||
- include_tasks: setup-OpenBSD.yml
|
||||
when: ansible_facts.os_family == 'OpenBSD'
|
||||
|
||||
- include_tasks: setup-Archlinux.yml
|
||||
when: ansible_facts.os_family == 'Archlinux'
|
||||
|
||||
- include_tasks: setup-Suse.yml
|
||||
when: ansible_facts.os_family == 'Suse'
|
||||
|
||||
# Vhost configuration.
|
||||
- import_tasks: vhosts.yml
|
||||
|
||||
# Nginx setup.
|
||||
- name: Copy nginx configuration in place.
|
||||
template:
|
||||
src: "{{ nginx_conf_template }}"
|
||||
dest: "{{ nginx_conf_file_path }}"
|
||||
owner: root
|
||||
group: "{{ root_group }}"
|
||||
mode: 0644
|
||||
validate: nginx -t -c %s
|
||||
notify:
|
||||
- reload nginx
|
||||
|
||||
- name: Ensure nginx service is running as configured.
|
||||
service:
|
||||
name: nginx
|
||||
state: "{{ nginx_service_state }}"
|
||||
enabled: "{{ nginx_service_enabled }}"
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Ensure nginx is installed.
|
||||
pacman:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: present
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Update apt cache.
|
||||
apt: update_cache=yes cache_valid_time=86400
|
||||
changed_when: false
|
||||
|
||||
- name: Ensure nginx is installed.
|
||||
apt:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: present
|
||||
default_release: "{{ nginx_default_release }}"
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- name: Update pkg cache.
|
||||
command: pkg update -f
|
||||
environment:
|
||||
ASSUME_ALWAYS_YES: "yes"
|
||||
tags: ['skip_ansible_lint']
|
||||
|
||||
- name: Ensure nginx is installed.
|
||||
pkgng:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: present
|
||||
|
||||
- name: Create logs directory.
|
||||
file:
|
||||
path: /var/log/nginx
|
||||
state: directory
|
||||
mode: 0755
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Ensure nginx is installed.
|
||||
openbsd_pkg:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: present
|
||||
|
||||
- name: Create logs directory.
|
||||
file:
|
||||
path: /var/log/nginx
|
||||
state: directory
|
||||
mode: 0755
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Enable nginx repo.
|
||||
template:
|
||||
src: nginx.repo.j2
|
||||
dest: /etc/yum.repos.d/nginx.repo
|
||||
owner: root
|
||||
group: "{{ root_group }}"
|
||||
mode: 0644
|
||||
when: nginx_yum_repo_enabled | bool
|
||||
|
||||
- name: Ensure nginx is installed.
|
||||
package:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: present
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Enable nginx repo.
|
||||
zypper_repository:
|
||||
name: nginx
|
||||
repo: http://nginx.org/packages/sles/{{ ansible_facts.distribution_major_version }}
|
||||
state: present
|
||||
disable_gpg_check: true
|
||||
autorefresh: true
|
||||
when: nginx_zypper_repo_enabled | bool
|
||||
|
||||
- name: Ensure nginx is installed.
|
||||
package:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: present
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
- name: Ensure dirmngr is installed (gnupg dependency).
|
||||
apt:
|
||||
name: dirmngr
|
||||
state: present
|
||||
|
||||
- name: Add PPA for Nginx (if configured).
|
||||
apt_repository:
|
||||
repo: 'ppa:nginx/{{ nginx_ppa_version }}'
|
||||
state: present
|
||||
update_cache: true
|
||||
register: nginx_ppa_added
|
||||
when: nginx_ppa_use | bool
|
||||
|
||||
- name: Ensure nginx will reinstall if the PPA was just added.
|
||||
apt:
|
||||
name: "{{ nginx_package_name }}"
|
||||
state: absent
|
||||
when: nginx_ppa_added is changed
|
||||
tags: ['skip_ansible_lint']
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
- name: Remove default nginx vhost config file (if configured).
|
||||
file:
|
||||
path: "{{ nginx_default_vhost_path }}"
|
||||
state: absent
|
||||
when: nginx_remove_default_vhost | bool
|
||||
notify: restart nginx
|
||||
|
||||
- name: Ensure nginx_vhost_path exists.
|
||||
file:
|
||||
path: "{{ nginx_vhost_path }}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
notify: reload nginx
|
||||
|
||||
- name: Add managed vhost config files.
|
||||
template:
|
||||
src: "{{ item.template|default(nginx_vhost_template) }}"
|
||||
dest: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
|
||||
force: true
|
||||
owner: root
|
||||
group: "{{ root_group }}"
|
||||
mode: 0644
|
||||
when: item.state|default('present') != 'absent'
|
||||
with_items: "{{ nginx_vhosts }}"
|
||||
notify: reload nginx
|
||||
tags:
|
||||
- skip_ansible_lint
|
||||
|
||||
- name: Remove managed vhost config files.
|
||||
file:
|
||||
path: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
|
||||
state: absent
|
||||
when: item.state|default('present') == 'absent'
|
||||
with_items: "{{ nginx_vhosts }}"
|
||||
notify: reload nginx
|
||||
tags:
|
||||
- skip_ansible_lint
|
||||
|
||||
- name: Remove legacy vhosts.conf file.
|
||||
file:
|
||||
path: "{{ nginx_vhost_path }}/vhosts.conf"
|
||||
state: absent
|
||||
notify: reload nginx
|
||||
Reference in New Issue
Block a user