Compare commits

...

14 Commits

Author SHA1 Message Date
0b25968d5d
feat(ldap-user-backend): add role for managing ldap user backend in nextcloud 2021-10-28 17:56:16 +02:00
b1a1daf955
fix(server): specify value type when configuring settings 2021-10-28 17:56:05 +02:00
341780731c
chore: bump version to 0.3.0 2021-10-24 16:08:25 +02:00
fe15b316bf
chore(server): populate managed config keys conditionally 2021-10-24 15:59:31 +02:00
e9715e31bf
feat(server): allow configuring nextcloud settings by populating nextcloud_extra_config 2021-10-24 15:50:35 +02:00
feadc801d5
chore(server): add a more descriptive task name 2021-10-24 14:12:05 +02:00
3b2957492e
fix(server): don't mark a lookup task as changed 2021-10-24 14:11:00 +02:00
dd5223afaa
chore(server): allow using a FPM socket 2021-10-24 12:38:43 +02:00
dd295b4129
chore(server): allow configuring dbhost even after first initialization 2021-10-21 22:21:24 +02:00
5d00b7637d
chore(server): allow configuring php memory limit and max upload size 2021-10-17 21:12:38 +02:00
5bc19d4ddc
chore(server): allow configuring common opcache and fpm optimizations 2021-10-17 21:03:40 +02:00
80317cae6a
chore(server): allow configuring nextcloud background job mode 2021-10-17 21:03:35 +02:00
f2e66f002b
chore: bump version to 0.2.0 2021-10-16 15:19:10 +02:00
1caf613ff2
chore: rename roles to reflect upstream naming scheme 2021-10-16 15:14:50 +02:00
24 changed files with 303 additions and 44 deletions

View File

@ -7,12 +7,12 @@ and managing nextcloud installations
## Roles
- [`roles/nextcloud`](roles/nextcloud/README.md): For deploying
- [`roles/server`](roles/server/README.md): For deploying
and configuring a bare nextcloud instance in a docker container.
Supports both the `-apache` (default) and `-fpm` variants.
- [`roles/nextcloud-apps`](roles/nextcloud-apps/README.md):
- [`roles/apps`](roles/apps/README.md):
For managing nextcloud apps in an already installed nextcloud
instance. Can install, remove, enable/disable and update apps.
server instance. Can install, remove, enable/disable and update apps.
## License

View File

@ -1,6 +1,6 @@
namespace: finallycoffee
name: nextcloud
version: 0.1.0
version: 0.3.0
readme: README.md
authors:
- Johanna Dorothea Reichmann <transcaffeine@finallycoffee.eu>

View File

@ -0,0 +1,19 @@
---
nc_ldap_api_instance_url: http://localhost
nc_ldap_api_basic_auth_user:
nc_ldap_api_basic_auth_password:
nc_ldap_config_id: s01
nc_ldap_config_host: 127.0.0.1
nc_ldap_config_port: 389
nc_ldap_config_backup_host: ~
nc_ldap_config_backup_port: ~
nc_ldap_config_base_dn:
nc_ldap_config_base_dn_users:
nc_ldap_config_base_dn_groups:
nc_ldap_config_agent_name:
nc_ldap_config_agent_password:
nc_ldap_meta_http_agent: "ansible-httpget/finallycoffee.nextcloud.ldap-user-backend"

View File

@ -0,0 +1,45 @@
---
- name: Default api config
meta: noop
vars: &api_defaults
http_agent: "{{ nc_ldap_meta_http_agent }}"
headers: "{{ nc_ldap_api_headers }}"
url_username: "{{ nc_ldap_api_basic_auth_user }}"
url_password: "{{ nc_ldap_api_basic_auth_password }}"
force_basic_auth: yes
force: yes
- name: Check if configuration with given config ID already exists
uri:
<<: *api_defaults
url: "{{ nc_ldap_api_path }}/{{ nc_ldap_config_id }}{{ query_params }}"
method: GET
vars:
query_params: "?showPassword=1&format={{nc_ldap_api_parameter_format }}"
register: nc_ldap_existing_config
# TODO: Can we force an ID on POST?
- name: Create ldap configuration with id={{ nc_ldap_config_id }}
uri:
<<: *api_defaults
url: "{{ nc_ldap_api_path }}"
method: POST
when: nc_ldap_existing_config.status != 200
- name: Create changeset
set_fact:
nc_ldap_config_changeset: "{{ nc_ldap_config_changeset | combine(changed_entry) }}"
vars:
changed_entry: "{{ { item : nc_ldap_config_keys[item] } }}"
loops: "{{ nc_ldap_config_keys.keys() }}"
when: "{{ nc_ldap_config_keys[item] is defined and nc_ldap_config_keys[item] is not None }}"
- name: Ensure ldap configuration is in sync
uri:
<<: *api_defaults
url:
method: PUT
body:
body_format: "form-urlencoded"

View File

@ -0,0 +1,58 @@
---
nc_ldap_api_path: "/ocs/v2.php/apps/user_ldap/api/v1/config"
nc_ldap_api_url: "{{ nc_ldap_api_instance_url }}{{ nc_ldap_api_path }}"
nc_ldap_api_headers:
OCS-APIREQUEST: "true"
nc_ldap_api_parameter_format: json
nc_ldap_config_keys:
ldapHost: "{{ nc_ldap_config_host }}"
ldapPort: "{{ nc_ldap_config_port }}"
ldapBackupHost: "{{ nc_ldap_config_backup_host }}"
ldapBackupPort: "{{ nc_ldap_config_backup_port }}"
ldapOverrideMainServer: "{{ nc_ldap_config_override_main_server }}"
ldapBase: "{{ nc_ldap_config_base_dn }}"
ldapBaseUsers: "{{ nc_ldap_config_base_dn_users }}"
ldapBaseGroups: "{{ nc_ldap_config_base_dn_groups }}"
ldapAgentName: "{{ nc_ldap_config_agent_name }}"
ldapAgentPassword: "{{ nc_ldap_config_agent_password }}"
ldapTLS: "{{ nc_ldap_config_tls }}"
turnOffCertCheck: "{{ nc_ldap_config_turn_off_cert_check }}"
ldapUserDisplayName: "{{ nc_ldap_config_user_displayname }}"
ldapUserDisplayName2: "{{ nc_ldap_config_user_displayname2 }}"
ldapUserAvatarRule: "{{ nc_ldap_config_user_avatar_rule }}"
ldapGidNumber: "{{ nc_ldap_config_gid_number }}"
ldapUserFilterObjectclass: "{{ nc_ldap_config_user_filter_objectclass }}"
ldapUserFilterGroups: "{{ nc_ldap_config_user_filter_groups }}"
ldapUserFilter: "{{ nc_ldap_config_user_filter }}"
ldapUserFilterMode: "{{ nc_ldap_config_user_filter_mode }}"
ldapAttributesForUserSearch: "{{ nc_ldap_config_attributes_for_user_search }}"
ldapGroupFilter: "{{ nc_ldap_config_group_filter }}"
ldapGroupFilterMode: "{{ nc_ldap_config_group_filter_mode }}"
ldapGroupFilterObjectclass: "{{ nc_ldap_config_group_filter_objectclass }}"
ldapGroupFilterGroups: "{{ nc_ldap_config_group_filter_groups }}"
ldapGroupMemberAssocAttr: "{{ nc_ldap_config_group_member_assoc_attr }}"
ldapGroupDisplayName: "{{ nc_ldap_config_group_displayname }}"
ldapAttributesForGroupSearch: "{{ nc_ldap_config_attributes_for_group_search }}"
ldapLoginFilter: "{{ nc_ldap_config_login_filter }}"
ldapLoginFilterMode: "{{ nc_ldap_config_login_filter_mode }}"
ldapLoginFilterEmail: "{{ nc_ldap_config_login_filter_email }}"
ldapLoginFilterUsername: "{{ nc_ldap_config_login_filter_username }}"
ldapLoginFilterAttributes: "{{ nc_ldap_config_login_filter_attributes }}"
ldapQuotaAttribute: "{{ nc_ldap_config_quota_attribute }}"
ldapQuotaDefault: "{{ nc_ldap_config_quota_default }}"
ldapEmailAttribute: "{{ nc_ldap_config_email_attribute }}"
ldapCacheTTL: "{{ nc_ldap_config_cache_ttl }}"
ldapConfigurationActive: "{{ nc_ldap_config_configuration_active }}"
ldapExperiencedAdmin: "{{ nc_ldap_config_experienced_admin }}"
homeFolderNamingRule: "{{ nc_ldap_config_home_folder_naming_rule }}"
useMemberOfToDetectMembership: "{{ nc_ldap_config_use_memberOf_to_detect_membership }}"
ldapExpertUsernameAttr: "{{ nc_ldap_config_expert_username_attr }}"
ldapExpertUUIDUserAttr: "{{ nc_ldap_config_expert_uuid_user_attr }}"
ldapExpertUUIDGroupAttr: "{{ nc_ldap_config_expert_uuid_group_attr }}"
ldapNestedGroups: "{{ nc_ldap_config_nested_groups }}"
ldapPagingSize: "{{ nc_ldap_config_paging_size }}"
turnOnPasswordChange: "{{ nc_ldap_config_turn_on_password_change }}"
ldapDynamicGroupMemberURL: "{{ nc_ldap_config_dynamic_group_member_url }}"
ldapDefaultPPolicyDN: "{{ nc_ldap_config_default_ppolicy_dn }}"

View File

@ -1,14 +0,0 @@
opcache.enable=1
opcache.interned_strings_buffer=32
; next prime in the set which is suitable for large installations
; default for this setting is 10000 which picks the prime 7963,
; but default installation of nextcloud has already ~9k php files
; see https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.max-accelerated-files
opcache.max_accelerated_files=32531
opcache.memory_consumption=256
; deconstructor optimizations
opcache.fast_shutdown=1
;opcache.save_comments=1
; not used if validate_timestamps=0
;opcache.revalidate_freq=1
opcache.validate_timestamps=0

View File

@ -1,14 +0,0 @@
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 64
pm.start_servers = 32
pm.min_spare_servers = 24
pm.max_spare_servers = 48
;pm.max_requests=500

View File

@ -6,3 +6,9 @@ regardless of wether the `apache` or `fpm` docker image is used.
It provides various common (optimization) configuration options
and creates a user on the host which is mapped into the container,
so the host file permissions remain comprehensible.
## Configuration
- `nextcloud_socket_path`: Setting this (to, for example, `{{ nextcloud_basepath }}/socket`),
will make FPM listen on `{{ nextcloud_socket_path }}/nextcloud.sock` on the host, enabling
you to use FPM to interface with nextcloud.

View File

@ -9,6 +9,9 @@ nextcloud_data_path: "{{ nextcloud_basepath }}/data"
# Where user data like media, documents etc are persisted
nextcloud_storage_path: "{{ nextcloud_basepath }}/storage"
nextcloud_fpm_config_path: "{{ nextcloud_basepath }}/fpm-config"
#nextcloud_socket_path: "{{ nextcloud_basepath }}/socket"
nextcloud_background_job_mode: cron
nextcloud_database_type: sqlite
nextcloud_database_name: nextcloud
@ -30,6 +33,7 @@ nextcloud_container_base_volumes:
- "{{ nextcloud_data_path }}:/var/www/html:z"
- "{{ nextcloud_fpm_config_path }}/opcache.ini:/usr/local/etc/php/conf.d/opcache-recommended.ini:z"
- "{{ nextcloud_fpm_config_path }}/fpm.ini:/usr/local/etc/php-fpm.d/www.conf:z"
- "{{ nextcloud_fpm_config_path }}/fpm-docker.ini:/usr/local/etc/php-fpm.d/zz-docker.conf:z"
- "{{ nextcloud_basepath }}/nextcloud-passwd:/etc/passwd:z"
- "{{ nextcloud_basepath }}/nextcloud-group:/etc/group:z"
nextcloud_container_extra_volumes: []
@ -56,3 +60,22 @@ nextcloud_paths:
mode: "0770"
owner: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
group: "root"
# PHP OpCache tuning
nextcloud_opcache_enable: 1
nextcloud_opcache_interned_strings_buffer_mb: 32
nextcloud_opcache_max_accelerated_files: 32531
nextcloud_opcache_memory_consumption_mb: 256
nextcloud_opcache_fast_shutdown: 1
nextcloud_opcache_save_comments: 1
nextcloud_opcache_revalidate_freq: 1
nextcloud_opcache_validate_timestamps: 0
# FPM config
nextcloud_fpm_max_children: 64
nextcloud_fpm_start_servers: "{{ nextcloud_fpm_max_children / 2 | int }}"
nextcloud_fpm_min_spare_servers: "{{ nextcloud_fpm_max_children / 4 | int }}"
nextcloud_fpm_max_spare_servers: "{{ nextcloud_fpm_max_children * 3/4 | int }}"
nextcloud_php_memory_limit: 1024M
nextcloud_php_upload_limit: 1024M

View File

@ -0,0 +1,40 @@
---
- name: Ensure {{ key }} is set to {{ value }}
block:
- name: Check value of {{ key }}
community.docker.docker_container_exec:
container: "{{ nextcloud_container_name }}"
command: "{{ nextcloud_occ_command }} config:{{ type }}:get {{ scope }} {{ entry }}"
user: "{{ nextcloud_user_info.uid }}"
tty: yes
register: nextcloud_current_config_entry
changed_when: false
- name: Set {{ key }} to {{ value }}
community.docker.docker_container_exec:
container: "{{ nextcloud_container_name }}"
command: "{{ nextcloud_occ_command }} config:{{ type }}:set {{ scope }} {{ entry }} --type={{ value_type }} --value={{ value }} -n"
user: "{{ nextcloud_user_info.uid }}"
tty: yes
when: nextcloud_current_config_entry.stdout != value
notify: restart-nextcloud
vars:
entry_path: "{{ key.split('.') }}"
value_type: >-
{% if value is boolean %}
boolean
{% elsif value is integer %}
integer
{% elsif value is float %}
float
{% else %}
string
{% endif %}
type: "{{ entry_path | first }}"
scope: "{{ entry_path[1] if entry_path | length > 2 else '' }}"
entry: >-
{{
entry_path[1] if entry_path|length == 2 else
(entry_path[2:] | join(" "))
}}

View File

@ -7,6 +7,19 @@
system: yes
register: nextcloud_user_info
- name: Map nextcloud socket path if defined
set_fact:
nextcloud_paths: "{{ nextcloud_paths + [ socket_dir ] }}"
nextcloud_container_base_volumes: "{{ nextcloud_container_base_volumes + [ socket_map ] }}"
vars:
socket_dir:
path: "{{ nextcloud_socket_path }}"
mode: "0755"
owner: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
group: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
socket_map: "{{ nextcloud_socket_path }}:{{ nextcloud_container_php_socket_path }}:z"
when: nextcloud_socket_path is defined and nextcloud_socket_path is string
- name: Ensure nextcloud directories exist and have correct permissions
file:
path: "{{ item.path }}"
@ -43,6 +56,16 @@
notify:
- reload-nextcloud
- name: Template PHP FPM docker-specific configuration
template:
src: nextcloud-fpm-docker.ini.j2
dest: "{{ nextcloud_fpm_config_path }}/fpm-docker.ini"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template modified /etc/passwd for nextcloud container
template:
src: nextcloud-passwd.j2
@ -70,6 +93,7 @@
mode: "0640"
owner: root
group: root
when: nextcloud_background_job_mode == 'cron'
notify:
- reload-systemd
@ -80,21 +104,12 @@
mode: "0640"
owner: root
group: root
when: nextcloud_background_job_mode == 'cron'
notify:
- reload-systemd
- meta: flush_handlers
- name: Enable systemd timer for nextcloud cron
systemd:
name: "nextcloud-cron.timer"
enabled: yes
- name: Ensure systemd timer for nextcloud cron is started
systemd:
name: "nextcloud-cron.timer"
state: started
- name: Flush handlers now to ensure systemd can know about the timer before it's enabled
meta: flush_handlers
- name: Ensure docker container for nextcloud is running
docker_container:
@ -107,3 +122,23 @@
purge_networks: "{{ nextcloud_container_purge_other_networks }}"
restart_policy: "{{ nextcloud_container_restart_policy }}"
state: started
- name: Enable systemd timer for nextcloud cron
systemd:
name: "nextcloud-cron.timer"
enabled: yes
when: nextcloud_background_job_mode == 'cron'
- name: Ensure systemd timer for nextcloud cron is started
systemd:
name: "nextcloud-cron.timer"
state: started
when: nextcloud_background_job_mode == 'cron'
- name: Configure nextcloud
include_tasks:
file: configure-single-setting.yml
vars:
key: "{{ item.key | replace('[', '.') | replace(']', '.') }}"
value: "{{ item.value }}"
loop: "{{ lookup('ansible.utils.to_paths', nextcloud_config ) | dict2items }}"

View File

@ -0,0 +1,2 @@
[global]
daemonize = no

View File

@ -0,0 +1,14 @@
opcache.enable={{ nextcloud_opcache_enable }}
opcache.interned_strings_buffer={{ nextcloud_opcache_interned_strings_buffer_mb }}
; next prime in the set which is suitable for large installations
; default for this setting is 10000 which picks the prime 7963,
; but default installation of nextcloud has already ~9k php files
; see https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.max-accelerated-files
opcache.max_accelerated_files={{ nextcloud_opcache_max_accelerated_files }}
opcache.memory_consumption={{ nextcloud_opcache_memory_consumption_mb }}
; deconstructor optimizations
opcache.fast_shutdown={{ nextcloud_opcache_fast_shutdown }}
opcache.save_comments={{ nextcloud_opcache_save_comments }}
; not used if validate_timestamps=0
opcache.revalidate_freq={{ nextcloud_opcache_revalidate_freq }}
opcache.validate_timestamps={{ nextcloud_opcache_validate_timestamps }}

View File

@ -0,0 +1,21 @@
[www]
user = www-data
group = www-data
{% if nextcloud_socket_path is defined and nextcloud_socket_path is string %}
listen = {{ nextcloud_container_php_socket_path }}/nextcloud.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
{% else %}
;listen = 0.0.0.0:9000
{% endif %}
pm = dynamic
pm.max_children = {{ nextcloud_fpm_max_children }}
pm.start_servers = {{ nextcloud_fpm_start_servers }}
pm.min_spare_servers = {{ nextcloud_fpm_min_spare_servers }}
pm.max_spare_servers = {{ nextcloud_fpm_max_spare_servers }}
;pm.max_requests=500

View File

@ -22,3 +22,27 @@ nextcloud_container_base_environment_yaml: |+2
{% elif nextcloud_database_type == 'sqlite' %}
SQLITE_DATABASE: "{{ nextcloud_database_name }}"
{% endif %}
PHP_MEMORY_LIMIT: "{{ nextcloud_php_memory_limit }}"
PHP_UPLOAD_LIMIT: "{{ nextcloud_php_upload_limit }}"
nextcloud_config: "{{ nextcloud_base_config | from_yaml | combine(nextcloud_extra_config|default({}), recursive=True, list_merge='append') }}"
nextcloud_base_config: |+2
{% if nextcloud_database_type != 'sqlite' %}
system:
dbhost: "{{ nextcloud_database_host }}"
dbuser: "{{ nextcloud_database_user }}"
dbpassword: "{{ nextcloud_database_pass }}"
dbname: "{{ nextcloud_database_name }}"
dbtype: "{{ nextcloud_database_types[nextcloud_database_type] }}"
{% endif %}
app:
core:
backgroundjobs_mode: "{{ nextcloud_background_job_mode }}"
nextcloud_occ_command: "php occ"
nextcloud_container_php_socket_path: /var/run/php
nextcloud_database_types:
postgres: pgsql
mysql: mysql
mariadb: mysql
sqlite: sqlite3