summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <microjoe@microjoe.org>2017-06-24 11:54:00 +0200
committerRomain Porte <microjoe@microjoe.org>2017-06-24 11:54:00 +0200
commit3c5842cd6ed3e465556b3603870ab1682d8d0fbd (patch)
tree96bc3d9ade11ff4f27589e5de22535d107a172a3
downloadMicroJoe.nginx-staticwebsite-3c5842cd6ed3e465556b3603870ab1682d8d0fbd.tar.gz
MicroJoe.nginx-staticwebsite-3c5842cd6ed3e465556b3603870ab1682d8d0fbd.zip
Initial commit
-rw-r--r--LICENSE19
-rw-r--r--README.md38
-rw-r--r--defaults/main.yml14
-rw-r--r--handlers/main.yml2
-rw-r--r--meta/main.yml57
-rw-r--r--tasks/main.yml36
-rw-r--r--templates/nginx.j262
-rw-r--r--tests/inventory2
-rw-r--r--tests/test.yml5
-rw-r--r--vars/main.yml2
10 files changed, 237 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..bda6513
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright 2017 Romain Porte
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..225dd44
--- /dev/null
+++ b/README.md
@@ -0,0 +1,38 @@
+Role Name
+=========
+
+A brief description of the role goes here.
+
+Requirements
+------------
+
+Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
+
+Role Variables
+--------------
+
+A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
+
+Dependencies
+------------
+
+A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
+
+Example Playbook
+----------------
+
+Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
+
+ - hosts: servers
+ roles:
+ - { role: username.rolename, x: 42 }
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+An optional section for the role authors to include contact information, or a website (HTML is not allowed).
diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..5db7a83
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,14 @@
+---
+# defaults file for MicroJoe.staticwebsite
+
+nginx_root: "/var/www/{{ nginx_domain }}/"
+nginx_filename: "static-{{ nginx_domain }}.conf"
+nginx_rewrite_html: false
+nginx_customize: ""
+
+letsencrypt_wellknown: /var/www/letsencrypt
+letsencrypt_activate: false
+letsencrypt_https: false
+
+upload_user: ssh-http-upload
+upload_group: www-data
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644
index 0000000..20bf98a
--- /dev/null
+++ b/handlers/main.yml
@@ -0,0 +1,2 @@
+---
+# handlers file for MicroJoe.staticwebsite \ No newline at end of file
diff --git a/meta/main.yml b/meta/main.yml
new file mode 100644
index 0000000..7223799
--- /dev/null
+++ b/meta/main.yml
@@ -0,0 +1,57 @@
+galaxy_info:
+ author: your name
+ description: your description
+ company: your company (optional)
+
+ # If the issue tracker for your role is not on github, uncomment the
+ # next line and provide a value
+ # issue_tracker_url: http://example.com/issue/tracker
+
+ # Some suggested licenses:
+ # - BSD (default)
+ # - MIT
+ # - GPLv2
+ # - GPLv3
+ # - Apache
+ # - CC-BY
+ license: license (GPLv2, CC-BY, etc)
+
+ min_ansible_version: 1.2
+
+ # If this a Container Enabled role, provide the minimum Ansible Container version.
+ # min_ansible_container_version:
+
+ # Optionally specify the branch Galaxy will use when accessing the GitHub
+ # repo for this role. During role install, if no tags are available,
+ # Galaxy will use this branch. During import Galaxy will access files on
+ # this branch. If Travis integration is configured, only notifications for this
+ # branch will be accepted. Otherwise, in all cases, the repo's default branch
+ # (usually master) will be used.
+ #github_branch:
+
+ #
+ # platforms is a list of platforms, and each platform has a name and a list of versions.
+ #
+ # platforms:
+ # - name: Fedora
+ # versions:
+ # - all
+ # - 25
+ # - name: SomePlatform
+ # versions:
+ # - all
+ # - 1.0
+ # - 7
+ # - 99.99
+
+ galaxy_tags: []
+ # List tags for your role here, one per line. A tag is a keyword that describes
+ # and categorizes the role. Users find roles by searching for tags. Be sure to
+ # remove the '[]' above, if you add tags to this list.
+ #
+ # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
+ # Maximum 20 tags per role.
+
+dependencies: []
+ # List your role dependencies here, one per line. Be sure to remove the '[]' above,
+ # if you add dependencies to this list. \ No newline at end of file
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..f32b490
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,36 @@
+---
+# tasks file for MicroJoe.staticwebsite
+
+- name: Make sure {{ upload_user }} user exists
+ user:
+ name: "{{ upload_user }}"
+ group: "{{ upload_group }}"
+
+- name: Make sure {{ upload_user }} has .ssh directory
+ file:
+ path: "/home/{{ upload_user }}/.ssh"
+ state: directory
+ owner: "{{ upload_user }}"
+ group: "{{ upload_group }}"
+
+- name: Make sure {{ upload_user }} has .ssh/authorized_keys file
+ file:
+ path: "/home/{{ upload_user }}/.ssh/authorized_keys"
+ state: touch
+ owner: "{{ upload_user }}"
+ group: "{{ upload_group }}"
+
+- name: Make sure root directory exists
+ file:
+ path: "{{ nginx_root }}"
+ state: directory
+ owner: "{{ upload_user }}"
+ group: "{{ upload_group }}"
+
+- name: Install nginx configuration file {{ nginx_filename }}
+ template:
+ src: templates/nginx.j2
+ dest: /etc/nginx/sites-available/{{ nginx_filename }}
+ owner: root
+ group: root
+ notify: restart nginx
diff --git a/templates/nginx.j2 b/templates/nginx.j2
new file mode 100644
index 0000000..6ee36ba
--- /dev/null
+++ b/templates/nginx.j2
@@ -0,0 +1,62 @@
+{# vim: set filetype=django : #}
+
+server {
+ listen 80;
+ listen [::]:80;
+
+ server_name {{ nginx_domain }};
+
+{% if letsencrypt_activate %}
+ location .well-known {
+ root {{ letsencrypt_wellknown }};
+ }
+
+{% if letsencrypt_https %}
+ location / {
+ rewrite ^(.*)$ https://{{ nginx_domain }}$1 permanent;
+ }
+}
+
+server {
+ listen 443 ssl;
+ listen [::]:443 ssl;
+
+ server_name {{ nginx_domain }};
+
+ ssl on;
+ ssl_certificate /etc/letsencrypt/live/{{ nginx_domain }}/fullchain.pem;
+ ssl_certificate_key /etc/letsencrypt/live/{{ nginx_domain }}/privkey.pem;
+
+ include /etc/nginx/snippets/ssl.conf;
+
+{% endif %}
+{% endif %}
+
+ root {{ nginx_root }};
+ index index.html index.htm index.nginx-debian.html;
+
+ location / {
+ {% if nginx_rewrite_html %}
+ try_files $uri $uri/ =404;
+ {% else %}
+ try_files $uri.html $uri/ =404;
+ {% endif %}
+ }
+
+ location ~ ~$ {
+ # deny access to temp editor files, e.g. "script.php~"
+ access_log off;
+ log_not_found off;
+ deny all;
+ }
+
+ location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
+ # cache static assets and compress them
+ gzip on;
+ expires max;
+ add_header Pragma public;
+ add_header Cache-Control "public, must-revalidate, proxy-revalidate";
+ }
+
+ {{ nginx_customize }}
+}
diff --git a/tests/inventory b/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/tests/inventory
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/tests/test.yml b/tests/test.yml
new file mode 100644
index 0000000..302c2d7
--- /dev/null
+++ b/tests/test.yml
@@ -0,0 +1,5 @@
+---
+- hosts: localhost
+ remote_user: root
+ roles:
+ - MicroJoe.staticwebsite \ No newline at end of file
diff --git a/vars/main.yml b/vars/main.yml
new file mode 100644
index 0000000..71c6dd9
--- /dev/null
+++ b/vars/main.yml
@@ -0,0 +1,2 @@
+---
+# vars file for MicroJoe.staticwebsite \ No newline at end of file