Skip to content

Commit

Permalink
validate Nextcloud config after modifying
Browse files Browse the repository at this point in the history
If the insertafter regex fails, the line is written at EOF. This was breaking the Nextcloud config.

See: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html

datadirectory was absent because I hadn't yet walked through the Nextcloud web-based setup wizard.
  • Loading branch information
meonkeys committed May 2, 2024
1 parent 4de0571 commit f1afacf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions mario/ansible/roles/services/files/php-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# Ansible discards stdout. Write to stderr so Ansible outputs something useful when this script exits nonzero (e.g. why PHP linting failed).
docker run --rm --interactive php:8.2-apache-bookworm php -l < "$1" | tr '\n' '|' > /dev/stderr
16 changes: 13 additions & 3 deletions mario/ansible/roles/services/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,33 @@
path: /data/nextcloud/root/config/config.php
register: nextcloud_config

# 'datadirectory' below is an arbitrary choice, it's just something that always
- name: Install PHP lint script
copy:
src: php-lint.sh
dest: /usr/local/bin/php-lint.sh
owner: root
group: root
mode: 0755

# 'CONFIG = array' below is an arbitrary choice, it's just something that always
# should exist in the Nextcloud config file

- name: Add phone region to Nextcloud config
lineinfile:
path: /data/nextcloud/root/config/config.php
regexp: 'default_phone_region'
line: " 'default_phone_region' => '{{ lookup('env', 'DEFAULT_PHONE_REGION') }}',"
insertafter: 'datadirectory'
insertafter: 'CONFIG = array'
validate: /usr/local/bin/php-lint.sh %s
when: nextcloud_config.stat.exists

- name: Define arbitrary maintenance window
lineinfile:
path: /data/nextcloud/root/config/config.php
regexp: 'maintenance_window_start'
line: " 'maintenance_window_start' => 100,"
insertafter: 'datadirectory'
insertafter: 'CONFIG = array'
validate: /usr/local/bin/php-lint.sh %s
when: nextcloud_config.stat.exists

- name: Install docker-compose shortcut script
Expand Down

0 comments on commit f1afacf

Please sign in to comment.