@@ -13,6 +13,7 @@
|
||||
- [ipmi_exporter](roles/ipmi_exporter/README.md)
|
||||
- [karma](roles/karma/README.md)
|
||||
- [mount_device](roles/mount_device/README.md)
|
||||
- [nginx](roles/nginx/README.md)
|
||||
- [prometheus](roles/prometheus/README.md)
|
||||
- [smartctl_exporter](roles/smartctl_exporter/README.md)
|
||||
- [ufw](roles/ufw/README.md)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
namespace: genlab
|
||||
name: common
|
||||
version: 0.13.0
|
||||
version: 0.14.0
|
||||
readme: README.md
|
||||
authors:
|
||||
- Alexander Gorelyshev (corvus-migratorius@proton.me)
|
||||
|
||||
2
roles/nginx/.gitignore
vendored
Normal file
2
roles/nginx/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.vscode
|
||||
.idea
|
||||
37
roles/nginx/README.md
Normal file
37
roles/nginx/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
ansible-nginx
|
||||
=========
|
||||
|
||||
Deploy NGINX with a minimal configuration.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
None
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
None
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
None
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
```yaml
|
||||
roles:
|
||||
- role: genlab.nginx
|
||||
```
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
BSD
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
corvus-migratorius@proton.me
|
||||
2
roles/nginx/defaults/main.yml
Normal file
2
roles/nginx/defaults/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
nginx_version: "1.26.3"
|
||||
16
roles/nginx/handlers/main.yml
Normal file
16
roles/nginx/handlers/main.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: "Update apt cache"
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: "Start nginx"
|
||||
ansible.builtin.service:
|
||||
name: nginx
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
- name: "Reload nginx"
|
||||
ansible.builtin.service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
17
roles/nginx/meta/main.yml
Normal file
17
roles/nginx/meta/main.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: "nginx"
|
||||
namespace: genlab
|
||||
author: "Alexander Gorelyshev"
|
||||
company: "Genlab, LLC"
|
||||
description: ""
|
||||
license: "MIT"
|
||||
min_ansible_version: "2.1"
|
||||
|
||||
platforms:
|
||||
- name: "Ubuntu"
|
||||
versions: ["focal", "jammy", "noble"]
|
||||
|
||||
galaxy_tags: []
|
||||
|
||||
dependencies: []
|
||||
36
roles/nginx/molecule/default/converge.yml
Normal file
36
roles/nginx/molecule/default/converge.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
post_tasks:
|
||||
- name: "Create a test site root"
|
||||
ansible.builtin.file:
|
||||
path: /var/www/html
|
||||
state: directory
|
||||
owner: nginx
|
||||
group: nginx
|
||||
mode: "0755"
|
||||
|
||||
- name: "Push a test index file"
|
||||
ansible.builtin.copy:
|
||||
src: index.html
|
||||
dest: /var/www/html
|
||||
owner: nginx
|
||||
group: nginx
|
||||
mode: "0644"
|
||||
|
||||
roles:
|
||||
# using default NGINX verison
|
||||
- role: genlab.common.nginx
|
||||
site:
|
||||
confname: test-var
|
||||
content: |
|
||||
server {
|
||||
listen 80;
|
||||
server_name example.com www.example.com;
|
||||
|
||||
location / {
|
||||
root /var/www/html;
|
||||
index index.html;
|
||||
}
|
||||
}
|
||||
dir_sites: '{{ lookup("env", "MOLECULE_PROJECT_DIRECTORY") }}/molecule/default/site-configs/'
|
||||
1
roles/nginx/molecule/default/files/index.html
Normal file
1
roles/nginx/molecule/default/files/index.html
Normal file
@@ -0,0 +1 @@
|
||||
Hello from ansible-nginx!
|
||||
27
roles/nginx/molecule/default/molecule.yml
Normal file
27
roles/nginx/molecule/default/molecule.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
|
||||
driver:
|
||||
name: docker
|
||||
|
||||
platforms:
|
||||
- name: ubuntu
|
||||
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
|
||||
pre_build_image: true
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
privileged: true
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
|
||||
verifier:
|
||||
name: ansible
|
||||
|
||||
lint: |
|
||||
set -e
|
||||
yamllint .
|
||||
ansible-lint .
|
||||
9
roles/nginx/molecule/default/site-configs/test-dir.conf
Normal file
9
roles/nginx/molecule/default/site-configs/test-dir.conf
Normal file
@@ -0,0 +1,9 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name test.com;
|
||||
|
||||
location / {
|
||||
root /var/www/html;
|
||||
index index.html;
|
||||
}
|
||||
}
|
||||
73
roles/nginx/molecule/default/verify.yml
Normal file
73
roles/nginx/molecule/default/verify.yml
Normal file
@@ -0,0 +1,73 @@
|
||||
# kics-scan disable=2e8d4922-8362-4606-8c14-aa10466a1ce3
|
||||
---
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
any_errors_fatal: true
|
||||
|
||||
pre_tasks:
|
||||
- name: "Include default vars"
|
||||
ansible.builtin.include_vars:
|
||||
dir: '{{ lookup("env", "MOLECULE_PROJECT_DIRECTORY") }}/defaults/'
|
||||
extensions:
|
||||
- 'yml'
|
||||
|
||||
tasks:
|
||||
- name: "Verify NGINX version"
|
||||
register: nginx_version_output
|
||||
changed_when: false
|
||||
failed_when: nginx_version_output.rc != 0
|
||||
ansible.builtin.command: /usr/sbin/nginx -v
|
||||
|
||||
# version is displayed as e.g. 'nginx version: nginx/1.26.3'
|
||||
- name: "Extract NGINX version"
|
||||
ansible.builtin.set_fact:
|
||||
nginx_version: "{{ nginx_version_output.stderr.split('/')[1] }}"
|
||||
|
||||
- name: "Check expected NGINX version"
|
||||
ansible.builtin.assert:
|
||||
that: nginx_version.startswith(nginx_version)
|
||||
fail_msg: "Unexpected NGINX version found: '{{ nginx_version }}'"
|
||||
|
||||
- name: "Gather service facts"
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: "Assert NGINX service is running"
|
||||
ansible.builtin.assert:
|
||||
that: ansible_facts.services['nginx.service'].state == 'running'
|
||||
fail_msg: "NGINX service is not running."
|
||||
|
||||
- name: "Assert NGINX service is enabled"
|
||||
ansible.builtin.assert:
|
||||
that: ansible_facts.services['nginx.service'].status == 'enabled'
|
||||
fail_msg: "NGINX service is not enabled."
|
||||
|
||||
- name: "Get an HTTP response from the test site (single site deployment from a variable)"
|
||||
register: nginx_response
|
||||
ansible.builtin.uri:
|
||||
url: http://localhost:80
|
||||
status_code: 200
|
||||
return_content: true
|
||||
|
||||
- name: "Check the response correctness on port 80"
|
||||
vars:
|
||||
message: "{{ nginx_response.content | trim }}"
|
||||
ansible.builtin.assert:
|
||||
that: message == 'Hello from ansible-nginx!'
|
||||
success_msg: "{{ message }}"
|
||||
fail_msg: "Unexpected response from the test site: '{{ message }}'"
|
||||
|
||||
- name: "Get an HTTP response from the test site (site deployment from a dictionary)"
|
||||
register: nginx_response
|
||||
ansible.builtin.uri:
|
||||
url: http://localhost:8080
|
||||
status_code: 200
|
||||
return_content: true
|
||||
|
||||
- name: "Check the response correctness on port 8080"
|
||||
vars:
|
||||
message: "{{ nginx_response.content | trim }}"
|
||||
ansible.builtin.assert:
|
||||
that: message == 'Hello from ansible-nginx!'
|
||||
success_msg: "{{ message }}"
|
||||
fail_msg: "Unexpected response from the test site: '{{ message }}'"
|
||||
53
roles/nginx/tasks/main.yml
Normal file
53
roles/nginx/tasks/main.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
- name: "Install gpg-agent"
|
||||
ansible.builtin.apt:
|
||||
name: gpg-agent
|
||||
state: present
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: "Add NGINX signing key"
|
||||
ansible.builtin.apt_key:
|
||||
url: https://nginx.org/keys/nginx_signing.key
|
||||
state: present
|
||||
|
||||
- name: "Add NGINX repository"
|
||||
notify: "Update apt cache"
|
||||
ansible.builtin.apt_repository:
|
||||
repo: "deb http://nginx.org/packages/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release }} nginx"
|
||||
state: present
|
||||
|
||||
- name: "Install specific NGINX version"
|
||||
notify: "Start nginx"
|
||||
ansible.builtin.apt:
|
||||
name: "nginx={{ nginx_version }}*"
|
||||
state: present
|
||||
|
||||
- name: "Remove default site configuration if it exists"
|
||||
notify: "Reload nginx"
|
||||
ansible.builtin.file:
|
||||
path: /etc/nginx/conf.d/default.conf
|
||||
state: absent
|
||||
|
||||
- name: "Deploy a single site configuration"
|
||||
when: site is defined
|
||||
notify: "Reload nginx"
|
||||
ansible.builtin.copy:
|
||||
dest: "/etc/nginx/conf.d/{{ site.confname }}.conf"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
content: "{{ site.content }}"
|
||||
|
||||
- name: "Deploy custom site configurations"
|
||||
when: dir_sites is defined
|
||||
with_fileglob:
|
||||
- "{{ dir_sites }}/*.conf"
|
||||
notify: "Reload nginx"
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/nginx/conf.d/{{ item | basename }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
# validate: '/usr/sbin/nginx -t -c %s'
|
||||
1
roles/nginx/vars/main.yml
Normal file
1
roles/nginx/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
---
|
||||
Reference in New Issue
Block a user