ansible-collection-nextcloud-admin
ansible-collection-nextcloud-admin copied to clipboard
nextcloud_config_settings has no effect after 1st installation
Hi
If we add (or remove) some parameters after the installation in "nextcloud_config_settings", it has only an effect on the 1st installation process, but not on a run after the installation.
The script checks the availability of the first domain, if not, the install script run the installation process, but this will fail.
We would like to change the config.php afterwords to configure apps, like this.
Thanks a lot Ivo
Hello there. @ivoruetsche , The current status of the role is indeed limited only to first installation to be "safe" as the config.php file is directly edited for the first Installation but after that the config file lives it's own life with the server. So its content can't be only determined only with ansible tasks or templates (unlike the apache/nginx config files). Knowing that, the best way to have some indepotence state of the server's config through ansible whould be to use only occ command line. I'm planning on extending the collection with further modules for managing the configuration but this requires further I vestigation. Also, I'm still learning ansible module/lookup development. For now I'm not able to get enough time to get some significant progress but the collection modules are still on my mind. 😉
Of course, any contribution is welcome 😄
Regards.
Aal.
Hi Aal
Thanks for the explanation - So, an outer ansible command will do the job now:
- name: "Configure config.php"
become_user: "{{ nextcloud_websrv_user }}"
become_flags: "{{ ansible_become_flags | default(omit) }}"
become: true
ansible.builtin.shell: |
if [ $(php occ config:system:get {{ item.name }} | grep -xc '{{ item.value }}') -eq 0 ]
then
php occ config:system:set {{ item.name }} --value='{{ item.value }}' || exit 1
echo changed
fi
args:
chdir: "{{ nextcloud_webroot }}"
loop: "{{ nextcloud_config_settings }}"
when: nextcloud_config_settings is defined and nextcloud_websrv_user is defined
register: output
changed_when: "'changed' in output.stdout"
Ivo
Hi Aal
Thanks for the explanation - So, an outer ansible command will do the job now:
- name: "Configure config.php" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: true ansible.builtin.shell: | if [ $(php occ config:system:get {{ item.name }} | grep -xc '{{ item.value }}') -eq 0 ] then php occ config:system:set {{ item.name }} --value='{{ item.value }}' || exit 1 echo changed fi args: chdir: "{{ nextcloud_webroot }}" loop: "{{ nextcloud_config_settings }}" when: nextcloud_config_settings is defined and nextcloud_websrv_user is defined register: output changed_when: "'changed' in output.stdout"
Ivo
Hello @ivoruetsche , there is one module in this collection that can simplify you this type of task if you want : A module for running occ commands directly : https://github.com/nextcloud/ansible-collection-nextcloud-admin#modules
You can get the module's doc with ansible-doc
command if you have installed the collection in your ansible environment.
Regards.
Hmm, I tried the nextcloud.admin.run_occ module, but it doesn't check the state, so I always get a "changed", even if it still set on nc.
Hmm, I tried the nextcloud.admin.run_occ module, but it doesn't check the state, so I always get a "changed", even if it still set on nc.
Hello there Yes this is intended purpose. As the content of the command is not interpreted and passed along. It mimic original command and shell modules. You ll have to define your task changed_when and failed_when conditions to get what you want. The module will help you write your occ command instead of using command and shell modules with a lot of elbow grease