diff --git a/playbook.yml b/playbook.yml index 5868130..8320fda 100644 --- a/playbook.yml +++ b/playbook.yml @@ -27,3 +27,11 @@ pelican_repo: https://github.com/AFPy/pyconfr_2010 pelican_path_in_repo: 2011/ pelican_home: "/srv/{{ pelican_user }}/" + +- hosts: pycons + roles: [static] + vars: + static_user: pycon2012 + static_https: true + static_domain: 2012.pycon.fr + static_repo: https://github.com/AFPy/pyconfr_2012 diff --git a/roles/static/defaults/main.yml b/roles/static/defaults/main.yml new file mode 100644 index 0000000..40a5aac --- /dev/null +++ b/roles/static/defaults/main.yml @@ -0,0 +1,6 @@ +static_user: pycon2010 +static_https: false +static_domain: some_static_website.pycon.fr +static_repo: https://github.com/AFPy/pyconfr_2010 +static_path_in_repo: 2010/ +static_home: "/srv/{{ static_user }}/" diff --git a/roles/static/handlers/main.yml b/roles/static/handlers/main.yml new file mode 100644 index 0000000..bcf145d --- /dev/null +++ b/roles/static/handlers/main.yml @@ -0,0 +1,4 @@ +--- + +- name: reload nginx + service: name=nginx state=reloaded diff --git a/roles/static/meta/main.yml b/roles/static/meta/main.yml new file mode 100644 index 0000000..b551e86 --- /dev/null +++ b/roles/static/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - { role: letsencrypt, domains: ["{{ static_domain }}"], when: static_https } diff --git a/roles/static/tasks/main.yml b/roles/static/tasks/main.yml new file mode 100644 index 0000000..ef74697 --- /dev/null +++ b/roles/static/tasks/main.yml @@ -0,0 +1,4 @@ +--- + +- include: static.yml + tags: static diff --git a/roles/static/tasks/static.yml b/roles/static/tasks/static.yml new file mode 100644 index 0000000..2f1d6bf --- /dev/null +++ b/roles/static/tasks/static.yml @@ -0,0 +1,27 @@ +--- + +- name: Install nginx and dependencies + apt: + name: [nginx, git] + +- name: Create user + user: + name: "{{ static_user }}" + shell: /bin/false + system: yes + home: "{{ static_home }}" + +- name: Clone repo + git: + repo: "{{ static_repo }}" + dest: "{{ static_home }}/www/" + register: clone_repo + +- name: Configure nginx + template: + src: nginx-vhost + dest: "/etc/nginx/conf.d/{{ static_domain }}.conf" + owner: root + group: root + mode: 0644 + notify: reload nginx diff --git a/roles/static/templates/nginx-vhost b/roles/static/templates/nginx-vhost new file mode 100644 index 0000000..66b3c99 --- /dev/null +++ b/roles/static/templates/nginx-vhost @@ -0,0 +1,33 @@ +{% if static_https %} +server { + listen 80; + server_name {{ static_domain }}; + + location / { + return 301 https://{{ static_domain }}$request_uri; + } +} + +server +{ + listen 443 ssl; + server_name {{ static_domain }}; + + include snippets/letsencrypt-{{ static_domain }}.conf; + + location / { + root {{ static_home }}/www/; + try_files $uri $uri/ =404; + } +} +{% else %} +server { + listen 80; + server_name {{ static_domain }}; + + location / { + root {{ static_home }}/www/; + try_files $uri $uri/ =404; + } +} +{% endif %}