commit db196d0567666ac657af581d97ff1f6863b7e223 Author: phil Date: Thu Dec 3 14:52:14 2020 +0000 Beginne Nextcloud-Rolle diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file 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..9d23639 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,15 @@ +--- +nextcloud_admin_pw: admin +nextcloud_admin_user: systemausfall.org +nextcloud_admin_pw: admin +nextcloud_database_host: database.kahlo +nextcloud_dl_url: https://download.nextcloud.com/server/releases +nextcloud_gateway: kahlo.kahlo +nextcloud_mysql_db: "nc_{{ common_name }}" +nextcloud_mysql_pw: admin +nextcloud_mysql_user: "nc_{{ common_name }}" +nextcloud_install_path: "/data/nextcloud/{{ nextcloud_domain }}" +nextcloud_trusted_domains: ['localhost', '{{ nextcloud_domain }}'] +nextcloud_version: nextcloud-20.0.2 + +php_version: "7.3" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..8cad331 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,21 @@ +--- +- name: reload apache + service: + name: apache2 + state: reloaded + +-name: restart apache + service: + name: apache2 + state: restarted + +- name: reload nginx + service: + name: nginx + state: reloaded + +- name: restart phpfpm + service: + name: "php{{ php_version }}-fpm" + state: restarted + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..c597a49 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,10 @@ +galaxy_info: + author: systemausfall.org + description: Role to deploy Nextcloud + company: Sense.Lab + license: GPLv3 + min_ansible_version: 2.4 + platforms: + - name: Debian + versions: + - Buster diff --git a/tasks/database.yml b/tasks/database.yml new file mode 100644 index 0000000..6025e5c --- /dev/null +++ b/tasks/database.yml @@ -0,0 +1,17 @@ +--- +- name: "Ensure nextcloud database exists" + mysql_db: + name: '{{ nextcloud_mysql_db }}' + state: present + config_file: /etc/mysql/debian.cnf + delegate_to: "{{ nextcloud_database_host }}" + +# Todo: Formatierung des Nutzernamens und Zuordnung des hosts schlaegt fehl +- name: "Ensure database user exists and has all privileges" + mysql_user: + name: "{{ nextcloud_mysql_user }}" + password: "{{ lookup('password', '/tmp/passwordfile chars=ascii_letters') }}" + priv: "{{ nextcloud_mysql_db }}.{{ inventory_hostname }}:ALL" + state: present + config_file: /etc/mysql/debian.cnf + delegate_to: "{{ nextcloud_database_host }}" diff --git a/tasks/gateway.yml b/tasks/gateway.yml new file mode 100644 index 0000000..5f8a31a --- /dev/null +++ b/tasks/gateway.yml @@ -0,0 +1,29 @@ +--- +- name: "Add domain to cerificate list" + lineinfile: + path: /etc/dehydrated/domains.txt + insertafter: "^# nextcloud" + line: "{{ nextcloud_domain }}" + # when: dehydrated_installiert + delegate_to: "{{ nextcloud_gateway }}" + +- name: "Obtain certificate" + command: dehydrated --cron -g + delegate_to: "{{ nextcloud_gateway }}" + +- name: "Copy webserver site configuration" + template: + src: nginx_site.j2 + dest: "/etc/nginx/sites-available/{{ nextcloud_domain }}" + owner: root + group: root + mode: 0644 + delegate_to: "{{ nextcloud_gateway }}" + +- name: "Enable site configuration" + file: + src: "/etc/nginx/sites-available/{{ nextcloud_domain }}" + dest: "/etc/nginx/sites-enabled/{{ nextcloud_domain }}" + state: link + notify: reload nginx + delegate_to: "{{ nextcloud_gateway }}" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..f64baf6 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,7 @@ +--- +- import_tasks: gateway.yml +- import_tasks: database.yml + tags: database +- import_tasks: nextcloud.yml + tags: nextcloud +- import_tasks: php.yml diff --git a/tasks/nextcloud.yml b/tasks/nextcloud.yml new file mode 100644 index 0000000..5c36216 --- /dev/null +++ b/tasks/nextcloud.yml @@ -0,0 +1,50 @@ +--- + +- name: "Ensure install dir is present" + file: + path: "{{ nextcloud_install_path }}" + mode: 0755 + state: directory + +- name: "Download und unarchive Nextcloud" + unarchive: + src: "{{ nextcloud_dl_url }}/{{ nextcloud_version }}.tar.bz2" + remote_src: true + extra_opts: + - "--strip-components=1" + dest: "{{ nextcloud_install_path }}" + owner: "{{ common_name }}" + group: "{{ common_name }}" + mode: 0755 + +- name: "Install Nextcloud" + command: > + php "{{ nextcloud_install_path }}"/occ maintenance:install --database "mysql" + --database-name "{{ nextcloud_mysql_db }}" --database-user "{{ nextcloud_mysql_user }}" + --database-pass 2CHbJwLpXTgHQkiUnFCgoowfT7vQdt85BX7VfRBCtb --database-host "{{ nextcloud_database_host }}" + --admin-user "{{ nextcloud_admin_user }}" --admin-pass "{{ nextcloud_admin_pw }}" + become: true + become_user: "{{ common_name }}" + changed_when: true + +- name: "Ensure trusted domains are set" + command: 'php {{ nextcloud_install_path }}/occ config:system:set trusted_domains {{ item.0 }} --value "{{ item.1 }}"' + become: true + become_user: "{{ common_name }}" + changed_when: true + with_indexed_items: + - '{{ nextcloud_trusted_domains }}' + +- name: "Ensure Apache marco module is loaded" + apache2_module: + state: present + name: macro + notify: restart apache + +- name: "Setup Apache site config" + lineinfile: + path: /etc/apache2/conf-available/nextcloud_sites.conf + insertafter: "^Ansbile" + line: "Use NCSite {{ nextcloud_domain }} {{ common_name }}" + state: present + notify: reload apache diff --git a/tasks/php.yml b/tasks/php.yml new file mode 100644 index 0000000..ba70526 --- /dev/null +++ b/tasks/php.yml @@ -0,0 +1,18 @@ +--- + +- name: "Create PHP-FPM-User" + user: + name: "{{ common_name }}" + create_home: no + password: "!" + shell: /bin/false + state: present + +- name: "Copy PHP-FPM configuration" + template: + src: php_fpm_pool.j2 + dest: "/etc/php/{{ php_version }}/fpm/pool.d/{{ common_name }}.conf" + owner: root + group: root + mode: 0644 + notify: restart phpfpm diff --git a/templates/nginx_site.j2 b/templates/nginx_site.j2 new file mode 100644 index 0000000..fcac02e --- /dev/null +++ b/templates/nginx_site.j2 @@ -0,0 +1,27 @@ +server { + listen 80; + server_name {{ nextcloud_domain }}; + include snippets/letsencrypt.conf; + location / { return 301 https://$http_host$request_uri; } +} + +server { + server_name {{ nextcloud_domain }}; + listen 443 ssl http2; + ssl_certificate /var/lib/dehydrated/certs/{{ nextcloud_domain }}/fullchain.pem; + ssl_certificate_key /var/lib/dehydrated/certs/{{ nextcloud_domain }}/privkey.pem; + include /etc/nginx/proxy_params; + add_header Referrer-Policy $referrerpolicy; + add_header Strict-Transport-Security $sts; + add_header X-Content-Type-Options $xcontentoptions; + add_header X-XSS-Protection $xxssprotection; +# include /etc/nginx/snippets/hpkp.conf; + + location ~ /.well-known/(carddav|caldav) { + return 301 $scheme://$host/remote.php/dav; + } + + location ~ \.* { + proxy_pass http://{{ inventory_hostname }}:80; + } +} \ No newline at end of file diff --git a/templates/php_fpm_pool.j2 b/templates/php_fpm_pool.j2 new file mode 100644 index 0000000..9b5c626 --- /dev/null +++ b/templates/php_fpm_pool.j2 @@ -0,0 +1,46 @@ +[{{ common_name }}] +;prefix = /path/to/pools/$pool +user = $pool +group = www-data +listen = /run/php/php-fpm-$pool.sock +;listen.backlog = 65535 +listen.owner = $pool +listen.group = www-data +listen.mode = 0660 +;listen.acl_users = +;listen.acl_groups = +listen.allowed_clients = 127.0.0.1 +pm = ondemand +pm.max_children = 5 +pm.start_servers = 2 +;pm.min_spare_servers = 2 +;pm.max_spare_servers = 5 +pm.process_idle_timeout = 10s; +pm.max_requests = 100 +;pm.status_path = /status +;ping.path = /ping +;ping.response = pong +;access.log = log/$pool.access.log +;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" +;slowlog = log/$pool.log.slow +;request_slowlog_timeout = 0 +;request_terminate_timeout = 0 +;rlimit_files = 1024 +;rlimit_core = 0 +;chroot = +chdir = / +;catch_workers_output = yes +;clear_env = no +security.limit_extensions = .php .php3 .php4 .php5 +;env[HOSTNAME] = $HOSTNAME +;env[PATH] = /usr/local/bin:/usr/bin:/bin +;env[TMP] = /tmp +;env[TMPDIR] = /tmp +;env[TEMP] = /tmp +;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com +;php_flag[display_errors] = off +;php_admin_value[error_log] = /var/log/fpm-php.www.log +;php_admin_flag[log_errors] = on +;php_admin_value[memory_limit] = 32M +php_admin_value[open_basedir] = {{ nextcloud_install_path }}:/tmp:/dev/urandom:/proc/meminfo:/var/log +;php_admin_value[disable_functions] = mail,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_exec,passthru,system,proc_get_status,proc_close,proc_nice,proc_terminate,proc_open,curl_ini,parse_ini_file,show_source,dl,symlink,system_exec,exec,shell_exec,phpinfo 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..2680d4e --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - nextcloud \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..b52587a --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nextcloud \ No newline at end of file