From 545162a46fe94797fb092325f4666950d8ef767e Mon Sep 17 00:00:00 2001 From: Tobias Hachmer Date: Fri, 27 Oct 2017 11:38:02 +0200 Subject: [PATCH] Add role service-nginx --- roles/handlers/handlers/main.yml | 5 ++ roles/service-nginx/README.md | 12 +++++ roles/service-nginx/files/style.css | 53 +++++++++++++++++++ roles/service-nginx/tasks/main.yml | 52 ++++++++++++++++++ roles/service-nginx/templates/default.conf.j2 | 12 +++++ roles/service-nginx/templates/index.html.j2 | 25 +++++++++ 6 files changed, 159 insertions(+) create mode 100644 roles/service-nginx/README.md create mode 100644 roles/service-nginx/files/style.css create mode 100644 roles/service-nginx/tasks/main.yml create mode 100644 roles/service-nginx/templates/default.conf.j2 create mode 100644 roles/service-nginx/templates/index.html.j2 diff --git a/roles/handlers/handlers/main.yml b/roles/handlers/handlers/main.yml index 3e86213..5ca2b47 100644 --- a/roles/handlers/handlers/main.yml +++ b/roles/handlers/handlers/main.yml @@ -88,3 +88,8 @@ - name: ip6tables-restore shell: ip6tables-restore < /etc/iptables/rules.v6 + +- name: reload nginx + systemd: + name: nginx + state: reloaded diff --git a/roles/service-nginx/README.md b/roles/service-nginx/README.md new file mode 100644 index 0000000..b45bba2 --- /dev/null +++ b/roles/service-nginx/README.md @@ -0,0 +1,12 @@ +# Ansible role service-nginx + +Diese Ansible role installiert und konfiguriert den Web Server nginx. + +- installiert das offizielle Debian Repository von nginx.org +- installiert nginx +- schreibt default.conf +- installiert die Standard MWU Gateway Webseite + +## Benötigte Variablen + +- Variable `inventory_hostname_short` diff --git a/roles/service-nginx/files/style.css b/roles/service-nginx/files/style.css new file mode 100644 index 0000000..1dea88f --- /dev/null +++ b/roles/service-nginx/files/style.css @@ -0,0 +1,53 @@ +body +{ + background: #ffffff; + color: #000000; + font-family: "Source Code Pro", "Consolas", "Courier New", "Monaco", monospace; + font-size: 12px; + white-space: nowrap; +} + +footer +{ + margin: 2em 0; +} + +a +{ + color: #ff4b57; +} + +.block +{ + margin: 1em; + padding: .5em; + border-radius: .5em; + border: #f9f9f9 1px solid; +} + +.cblock +{ + background: #000000; + color: #ffffff; + margin: 1em; + padding: .5em; + border-radius: .5em; + display: block; +} + +.ifblock +{ + display: inline-block; + vertical-align: top; + text-align: center; + margin: .1em; + padding: .5em; + min-width: 10em; + border: #f9f9f9 1px solid; + border-radius: .5em; +} + +.ifimg +{ + display: block; +} diff --git a/roles/service-nginx/tasks/main.yml b/roles/service-nginx/tasks/main.yml new file mode 100644 index 0000000..912e588 --- /dev/null +++ b/roles/service-nginx/tasks/main.yml @@ -0,0 +1,52 @@ +--- +- name: add official nginx apt key + apt_key: + state: present + id: 7BD9BF62 + url: "https://nginx.org/keys/nginx_signing.key" + +- name: add official nginx apt repository + apt_repository: + state: present + repo: "{{ item }}" + update_cache: yes + filename: nginx + with_items: + - deb http://nginx.org/packages/debian/ stretch nginx + - deb-src http://nginx.org/packages/debian/ stretch nginx + +- name: install nginx packages + package: + name: nginx + state: present + +- name: write nginx configuration default.conf + template: + src: default.conf.j2 + dest: /etc/nginx/conf.d/default.conf + mode: 0644 + notify: reload nginx + +- name: manage html directory for static files + file: + path: /var/www/html/static + state: directory + mode: 0755 + +- name: copy css stylesheet + copy: + src: style.css + dest: /var/www/html/static/style.css + mode: 0644 + +- name: write index.html + template: + src: index.html.j2 + dest: /var/www/html/index.html + mode: 0644 + +- name: configure systemd unit nginx + systemd: + name: nginx + state: started + enabled: yes diff --git a/roles/service-nginx/templates/default.conf.j2 b/roles/service-nginx/templates/default.conf.j2 new file mode 100644 index 0000000..15892b6 --- /dev/null +++ b/roles/service-nginx/templates/default.conf.j2 @@ -0,0 +1,12 @@ +server { + listen 80 default_server; + server_name _; + + charset utf-8; + server_tokens off; + + root /var/www/html; + location / { + index index.html; + } +} diff --git a/roles/service-nginx/templates/index.html.j2 b/roles/service-nginx/templates/index.html.j2 new file mode 100644 index 0000000..eb8c0fd --- /dev/null +++ b/roles/service-nginx/templates/index.html.j2 @@ -0,0 +1,25 @@ + + + + + Freifunk MWU Gateway "{{ inventory_hostname_short }}" + + + + + +
+

Freifunk MWU Gateway {{ inventory_hostname_short }}

+
+
Firmware
+
Traffic
+ +