added nginx role

This commit is contained in:
2024-12-04 15:38:14 +01:00
parent 996b0ce4ee
commit 9bbf0a37c0
10 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
# This file loads the proper rgloader/loader.rb file that comes packaged
# with Vagrant so that encoded files can properly run with Vagrant.
if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
require File.expand_path(
"rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"])
else
raise "Encoded files can't be read outside of the Vagrant installer."
end

View File

@@ -0,0 +1,11 @@
# Need to be in var file
#domain_name: kazcynski.duckdns.org
#nginx_root: kazcynski # /var/www/"{{ nginx_root }}" is the folder where the website files reside
packages:
- nginx
nginx_root_path: /var/www
nginx_config_dir: /etc/nginx/sites-available
nginx_sites_enabled: /etc/nginx/sites-enabled

View File

@@ -0,0 +1,4 @@
- name: Restart nginx
service:
name: nginx
state: reloaded

View File

@@ -0,0 +1,9 @@
---
- name: link nginx config to sites-enabled dir
ansible.builtin.file:
src: "{{ nginx_config_dir }}/{{ domain_name }}"
dest: "{{ nginx_sites_enabled }}/{{ domain_name }}"
owner: root
group: root
state: link
notify: Restart nginx

View File

@@ -0,0 +1,9 @@
---
- name: Install and enable nginx
include_tasks: nginx.yml
- name: Template config files into place
include_tasks: template.yml
- name: Enable site by linking to the dir "{{ nginx_sites_enabled }}"
include_tasks: link.yml

View File

@@ -0,0 +1,10 @@
- name: Install nginx
package:
name: nginx
state: present
- name: Enable nginx
service:
name: nginx
state: started
enabled: yes

View File

@@ -0,0 +1,39 @@
---
- name: ensure target dirs exists
file:
path: "{{ item }}"
state: directory
owner: root
group: root
loop:
- "{{ nginx_config_dir }}"
- name: ensure target dirs exists
file:
path: "{{ item }}"
state: directory
owner: "{{ main_username }}"
group: root
loop:
- "{{ nginx_root_path }}/{{ nginx_root }}"
- name: change hostname to domain_name
template:
src: ../templates/hostname.j2
dest: "/etc/hostname"
owner: root
group: root
- name: write homepage nginx config file
template:
src: ../templates/nginx-config.j2
dest: "{{ nginx_config_dir }}/{{ domain_name }}"
owner: root
group: root
- name: write simple homepage index.html file
template:
src: ../templates/index.html.j2
dest: "{{ nginx_root_path }}/{{ nginx_root }}/index.html"
owner: "{{ main_username }}"
group: root

View File

@@ -0,0 +1 @@
"{{ domain_name }}"

View File

@@ -0,0 +1,4 @@
<!DOCTYPE html>
<h1>Congratulations!</h1>
<p>The web server is running! </p>
<p>And serving this webpage on port 80.</p>

View File

@@ -0,0 +1,10 @@
server {
listen 80 ;
listen [::]:80 ;
server_name {{ domain_name }} ;
root /var/www/{{ nginx_root }} ;
index index.html index.htm index.nginx-debian.html ;
location / {
try_files $uri $uri/ =404 ;
}
}