2020-02-05 20:23:20 -06:00
|
|
|
#!/usr/bin/ansible-playbook
|
|
|
|
# vim:ft=ansible:
|
|
|
|
---
|
|
|
|
- name: Install, configure, and start Nextcloud
|
|
|
|
block:
|
|
|
|
- name: Install Nextcloud-required packages
|
|
|
|
apt:
|
|
|
|
name: "{{ packages }}"
|
|
|
|
vars:
|
|
|
|
packages:
|
|
|
|
- apache2
|
|
|
|
- mariadb-server
|
2020-02-05 21:54:30 -06:00
|
|
|
- libapache2-mod-php7.2
|
2020-02-05 20:23:20 -06:00
|
|
|
- php7.2
|
|
|
|
- php7.2-gd
|
2020-02-05 21:54:30 -06:00
|
|
|
- php7.2-json
|
2020-02-05 20:23:20 -06:00
|
|
|
- php7.2-mysql
|
2020-02-05 21:54:30 -06:00
|
|
|
- php7.2-curl
|
2020-02-05 20:23:20 -06:00
|
|
|
- php7.2-mbstring
|
2020-02-05 21:54:30 -06:00
|
|
|
- php7.2-intl
|
|
|
|
- php-imagick
|
|
|
|
- php7.2-xml
|
|
|
|
- php7.2-zip
|
|
|
|
- php7.2-cgi
|
|
|
|
- php7.2-cli
|
2020-02-05 20:23:20 -06:00
|
|
|
- python-openssl # Needed for keygen
|
|
|
|
- name: Copy configuration
|
2020-02-05 21:26:03 -06:00
|
|
|
copy:
|
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "{{ item.dest }}"
|
|
|
|
mode: "{{ item.mode }}"
|
|
|
|
loop:
|
|
|
|
- { src: "php-apache2.ini", dest: "/etc/php/7.2/apache2/php.ini", mode: "0644" }
|
|
|
|
- { src: "php-cgi.ini", dest: "/etc/php/7.2/cgi/php.ini", mode: "0644" }
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Set up Apache
|
|
|
|
block:
|
2020-02-05 22:28:03 -06:00
|
|
|
- name: Disable default configuration
|
|
|
|
file:
|
|
|
|
# This is a symlink so who cares
|
|
|
|
path: "/etc/apache2/sites-enabled/000-default.conf"
|
|
|
|
state: absent
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Create webroot
|
|
|
|
file:
|
2020-02-05 22:09:35 -06:00
|
|
|
path: "{{ nextcloud_webroot }}"
|
2020-02-05 22:14:35 -06:00
|
|
|
mode: "0755"
|
2020-02-05 21:54:30 -06:00
|
|
|
recurse: yes
|
|
|
|
state: directory
|
|
|
|
- name: Check for existing installation
|
|
|
|
stat:
|
2020-02-05 22:09:35 -06:00
|
|
|
path: "{{ nextcloud_webroot }}/index.html"
|
2020-02-05 21:54:30 -06:00
|
|
|
register: stat_webroot_index
|
|
|
|
- name: Install Nextcloud
|
|
|
|
block:
|
|
|
|
- name: Download Nextcloud
|
|
|
|
get_url:
|
2020-02-05 21:56:33 -06:00
|
|
|
dest: /var/www/nextcloud.tar.bz2
|
|
|
|
url: "{{ nextcloud_tarbz2 }}"
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Extract Nextcloud
|
|
|
|
unarchive:
|
2020-02-05 21:58:04 -06:00
|
|
|
src: /var/www/nextcloud.tar.bz2
|
|
|
|
remote_src: yes
|
2020-02-05 22:09:35 -06:00
|
|
|
dest: "{{ nextcloud_webroot }}"
|
2020-02-05 21:54:30 -06:00
|
|
|
extra_opts: [--strip-components=1]
|
2020-02-05 22:48:21 -06:00
|
|
|
- name: Chown webroot
|
|
|
|
file:
|
|
|
|
path: "{{ nextcloud_webroot }}"
|
|
|
|
state: directory
|
|
|
|
recurse: yes
|
|
|
|
owner: root
|
|
|
|
group: root
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Cleanup
|
|
|
|
file:
|
2020-02-05 22:12:56 -06:00
|
|
|
path: /var/www/nextcloud.tar.bz2
|
2020-02-05 21:54:30 -06:00
|
|
|
state: absent
|
|
|
|
when: not stat_webroot_index.stat.exists
|
2020-02-05 22:28:03 -06:00
|
|
|
- name: Enable Apache configs and modules
|
|
|
|
shell: "{{ item }}"
|
|
|
|
loop:
|
2020-02-05 22:30:30 -06:00
|
|
|
- "a2enmod rewrite"
|
|
|
|
- "a2enmod ssl"
|
2020-02-05 20:23:20 -06:00
|
|
|
- name: Register certificates
|
|
|
|
block:
|
2020-02-05 23:19:07 -06:00
|
|
|
- name: Set up PKI filesystem hierarchy
|
2020-02-05 20:23:20 -06:00
|
|
|
file:
|
|
|
|
path: "{{ item.dir }}"
|
|
|
|
mode: "{{ item.mode }}"
|
|
|
|
recurse: yes
|
2020-02-05 22:48:21 -06:00
|
|
|
owner: root
|
|
|
|
group: www-data
|
2020-02-05 20:23:20 -06:00
|
|
|
state: directory
|
|
|
|
loop:
|
2020-02-05 22:48:21 -06:00
|
|
|
- { dir: "/etc/pki", mode: "0750" }
|
|
|
|
- { dir: "/etc/pki/cert", mode: "0750" }
|
|
|
|
- { dir: "/etc/pki/cert/crt", mode: "0750" }
|
|
|
|
- { dir: "/etc/pki/cert/csr", mode: "0750" }
|
|
|
|
- { dir: "/etc/pki/cert/private", mode: "0750" }
|
2020-02-05 20:23:20 -06:00
|
|
|
- name: Create ACME account key
|
|
|
|
openssl_privatekey:
|
|
|
|
path: "/etc/pki/cert/private/account.key"
|
|
|
|
size: 4096
|
2020-02-05 21:06:44 -06:00
|
|
|
- name: Create certificate key
|
|
|
|
openssl_privatekey:
|
2020-02-05 22:09:35 -06:00
|
|
|
path: "/etc/pki/cert/private/{{ nextcloud_url }}.key"
|
2020-02-05 21:06:44 -06:00
|
|
|
size: 4096
|
2020-02-05 20:23:20 -06:00
|
|
|
- name: Create CSR
|
|
|
|
openssl_csr:
|
2020-02-05 22:09:35 -06:00
|
|
|
path: "/etc/pki/cert/csr/{{ nextcloud_url }}.csr"
|
|
|
|
common_name: "{{ nextcloud_url }}"
|
2020-02-05 23:01:06 -06:00
|
|
|
privatekey_path: /etc/pki/cert/private/{{ nextcloud_url }}.key
|
2020-02-05 20:23:20 -06:00
|
|
|
email_address: "rehashedsalt@cock.li"
|
2020-02-05 21:06:44 -06:00
|
|
|
- name: Create challenge for CSR
|
2020-02-05 20:23:20 -06:00
|
|
|
acme_certificate:
|
|
|
|
acme_directory: "https://acme-staging-v02.api.letsencrypt.org/directory"
|
|
|
|
acme_version: 2
|
|
|
|
terms_agreed: yes
|
|
|
|
account_email: "rehashedsalt@cock.li"
|
2020-02-05 21:06:44 -06:00
|
|
|
account_key: "/etc/pki/cert/private/account.key"
|
2020-02-05 22:09:35 -06:00
|
|
|
csr: "/etc/pki/cert/csr/{{ nextcloud_url }}.csr"
|
|
|
|
dest: "/etc/pki/cert/crt/{{ nextcloud_url }}.crt"
|
|
|
|
fullchain_dest: "/etc/pki/cert/crt/{{ nextcloud_url }}-fullchain.crt"
|
2020-02-05 21:06:44 -06:00
|
|
|
register: com_challenge
|
|
|
|
- name: Fulfill challenge
|
2020-02-05 23:19:07 -06:00
|
|
|
block:
|
|
|
|
- name: Configure insecure virtual host configs
|
|
|
|
template:
|
|
|
|
src: apache2-vhost.conf
|
|
|
|
dest: "/etc/apache2/sites-enabled/{{ nextcloud_url }}.conf"
|
|
|
|
- name: Reload Apache
|
|
|
|
service:
|
|
|
|
name: apache2
|
|
|
|
state: reloaded
|
|
|
|
- name: Create well-known directory
|
|
|
|
file:
|
|
|
|
path: "{{ nextcloud_webroot }}/.well-known/acme-challenge"
|
|
|
|
mode: "0755"
|
|
|
|
recurse: yes
|
|
|
|
state: directory
|
|
|
|
- name: Copy challenge files
|
|
|
|
copy:
|
|
|
|
dest: "{{ nextcloud_webroot }}/{{ com_challenge['challenge_data'][nextcloud_url]['http-01']['resource'] }}"
|
|
|
|
content: "{{ com_challenge['challenge_data'][nextcloud_url]['http-01']['resource_value'] }}"
|
|
|
|
- name: Create certificate
|
|
|
|
acme_certificate:
|
|
|
|
acme_directory: "https://acme-staging-v02.api.letsencrypt.org/directory"
|
|
|
|
acme_version: 2
|
|
|
|
account_key: /etc/pki/cert/private/account.key
|
|
|
|
csr: "/etc/pki/cert/csr/{{ nextcloud_url }}.csr"
|
|
|
|
dest: "/etc/pki/cert/crt/{{ nextcloud_url }}.crt"
|
|
|
|
fullchain_dest: "/etc/pki/cert/crt/{{ nextcloud_url }}-fullchain.crt"
|
|
|
|
chain_dest: "/etc/pki/cert/crt/{{ nextcloud_url }}-intermediate.crt"
|
|
|
|
data: "{{ com_challenge }}"
|
|
|
|
- name: Clean up
|
|
|
|
file:
|
|
|
|
path: "{{ nextcloud_webroot }}/.well-known"
|
|
|
|
state: absent
|
2020-02-05 21:06:44 -06:00
|
|
|
when: com_challenge is changed
|
2020-02-05 22:59:14 -06:00
|
|
|
- name: Secure Apache
|
|
|
|
block:
|
2020-02-05 23:19:07 -06:00
|
|
|
- name: Copy over virtual host configs
|
2020-02-05 22:59:14 -06:00
|
|
|
template:
|
|
|
|
src: apache2-vhost-ssl.conf
|
|
|
|
dest: "/etc/apache2/sites-enabled/{{ nextcloud_url }}.conf"
|
|
|
|
- name: Reload Apache
|
|
|
|
service:
|
|
|
|
name: apache2
|
|
|
|
state: reloaded
|
2020-02-05 21:13:04 -06:00
|
|
|
become: yes
|