Skip to content

Commit

Permalink
nextcloud: Add config.php restoration options.
Browse files Browse the repository at this point in the history
  • Loading branch information
JGoutin committed Jul 26, 2024
1 parent 05f89e0 commit d9d75d8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
17 changes: 17 additions & 0 deletions roles/nextcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ and should not be used on a publicly accessible server.*)
It is also recommended looking at the [**common**](../common/README.md) role variables
to customize the server OS (SSH, NTP, Firewall, and more).

### Optional Nexcloud restoration variables

| Name | Default Value | Description |
|-----------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `nextcloud_instance_id` | | `instanceid` value from a prior Nextcloud installation `config.php` to restore. `nextcloud_password_salt` & `nextcloud_secret` are also required. |
| `nextcloud_password_salt` | | `passwordsalt` value from a prior Nextcloud installation `config.php` to restore. `nextcloud_instance_id` & `nextcloud_secret` are also required. |
| `nextcloud_secret` | | `secret` value from a prior Nextcloud installation `config.php` to restore. `nextcloud_instance_id` & `nextcloud_password_salt` are also required. |
| `nextcloud_db_table_prefix` | `oc_` | `dbtableprefix` value from a prior Nextcloud installation `config.php` to restore. `nextcloud_instance_id`, `nextcloud_password_salt`, `nextcloud_secret` are also required. |

See the "Data to backup" section for more information on backup and restore of your Nextcloud installation.

## Example Playbook

```yaml
Expand Down Expand Up @@ -135,6 +146,12 @@ attention:
It requires regular backups to avoid data loss. Mounting this directory on a NAS
volume or similar is recommended.

It's now possible to restore a previous Nextcloud installation with this role:

- Ensure that `/var/lib/nextcloud` contains data exported from the backup
- Pass `nextcloud_instance_id`, `nextcloud_password_salt`, `nextcloud_secret` and
`nextcloud_db_table_prefix` to the role using values from the backup `config.php`.

## Upgrades

### Fedora version upgrade
Expand Down
24 changes: 24 additions & 0 deletions roles/nextcloud/tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
no_log: true
become: true
become_user: nextcloud
when:
- nextcloud_password_salt is not defined
- nextcloud_secret is not defined

- name: Retrieve nextcloud installed version
ansible.builtin.slurp:
src: /var/www/nextcloud/version.php
register: _nextcloud_version
when:
- nextcloud_password_salt is defined
- not _config_php.stat.exists

- name: Ensure Nextcloud is initialized from existing configuration
ansible.builtin.template:
src: config.php.j2
dest: /var/www/nextcloud/config/config.php
owner: nextcloud
group: nextcloud
mode: "0750"
setype: httpd_sys_rw_content_t
seuser: unconfined_u
when:
- nextcloud_password_salt is defined
- not _config_php.stat.exists

- name: Ensure Nextcloud configuration is set
ansible.builtin.command: '/usr/bin/php occ -n config:system:set {{ item.name }}
Expand Down
25 changes: 25 additions & 0 deletions roles/nextcloud/templates/config.php.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$CONFIG = [
'trusted_domains' =>
array (
0 => 'localhost',
),
'instanceid' => '{{ nextcloud_instance_id }}',
'passwordsalt' => '{{ nextcloud_password_salt }}',
'secret' => '{{ nextcloud_secret }}',
'datadirectory' => '/var/lib/nextcloud/data',
'dbtype' => 'pgsql',
'dbhost' => '/var/run/postgresql',
'dbport' => '',
'dbname' => 'nextcloud',
'dbuser' => 'nextcloud',
'dbpassword' => '',
'dbtableprefix' => '{{ nextcloud_db_table_prefix | default('oc_') }}',
'installed' => true,
'logfile' => '',
'log_type' => 'syslog',
'syslog_tag' => 'nextcloud',
'version' => '{{ (_nextcloud_version.content | b64decode | regex_search('OC_Version = array\((\d+,\d+,\d+,\d+)\)', '\\1'))[0] | regex_replace(',', '.') }}',
'overwrite.cli.url' => 'http://localhost',
'updater.release.channel' => 'stable',
];

0 comments on commit d9d75d8

Please sign in to comment.