diff --git a/molecule/default/roles/test_install_nextcloud/tasks/test_config_php.yml b/molecule/default/roles/test_install_nextcloud/tasks/test_config_php.yml index 3078ec42..ef0ae2c7 100644 --- a/molecule/default/roles/test_install_nextcloud/tasks/test_config_php.yml +++ b/molecule/default/roles/test_install_nextcloud/tasks/test_config_php.yml @@ -1,11 +1,9 @@ --- - name: "Get the config.php content" - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: php occ config:list - args: - chdir: "{{ nextcloud_webroot }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:list register: _config_php changed_when: _config_php.rc != 0 diff --git a/roles/backup/tasks/finishing.yml b/roles/backup/tasks/finishing.yml index dc499791..80d3ebd4 100644 --- a/roles/backup/tasks/finishing.yml +++ b/roles/backup/tasks/finishing.yml @@ -17,11 +17,10 @@ state: absent - name: Leave maintenance mode - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ maintenance:mode --off" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: maintenance:mode --off" become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: __leave_maintenance changed_when: - __leave_maintenance.stdout | regex_search('already') == none diff --git a/roles/backup/tasks/main.yml b/roles/backup/tasks/main.yml index b902b1c4..61492945 100644 --- a/roles/backup/tasks/main.yml +++ b/roles/backup/tasks/main.yml @@ -10,11 +10,10 @@ tags: - always - name: Enter maintenance mode - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ maintenance:mode --on" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: maintenance:mode --on" become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: __goto_maintenance changed_when: - __goto_maintenance.stdout | regex_search('already') == none diff --git a/roles/backup/tasks/nc_facts.yml b/roles/backup/tasks/nc_facts.yml index d20887a8..01429705 100644 --- a/roles/backup/tasks/nc_facts.yml +++ b/roles/backup/tasks/nc_facts.yml @@ -6,20 +6,18 @@ failed_when: false - name: Get nextcloud status - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ status --output=json" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: status --output=json become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: _nc_status changed_when: false - name: Get Nextcloud instance ID - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get instanceid" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get instanceid become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: _nc_id changed_when: false when: nextcloud_backup_app_data or nextcloud_backup_user @@ -30,11 +28,10 @@ - nextcloud_data_dir|d('') == '' block: - name: Get the data directory - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get datadirectory" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get datadirectory become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: nc_data_dir changed_when: false - name: Set missing fact @@ -42,20 +39,18 @@ nextcloud_data_dir: "{{ nc_data_dir.stdout }}" - name: Get the list of apps installed - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ app:list --output=json" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: app:list --output=json become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: _nc_app_list changed_when: false - name: Get the list of users - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ user:list --output=json" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: user:list --output=json become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" register: _nc_user_list changed_when: false when: @@ -64,29 +59,36 @@ - name: Find the DB credential if required when: - nextcloud_backup_database - become_user: "{{ nextcloud_websrv_user }}" become: true - become_method: "{{ occ_become_method }}" - become_flags: "{{ occ_become_flags }}" block: - name: Get database type - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get dbtype" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get dbtype register: _nc_dbtype changed_when: false - name: Get DB host - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get dbhost" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get dbhost register: _nc_dbhost changed_when: false - name: Get DB name - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get dbname" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get dbname register: _nc_dbname changed_when: false - name: Get DB user - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get dbuser" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get dbuser register: _nc_dbuser changed_when: false - name: Get DB password - ansible.builtin.command: "php {{ nextcloud_webroot }}/occ config:system:get dbpassword" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: config:system:get dbpassword register: _nc_dbpassword changed_when: false no_log: true diff --git a/roles/install_nextcloud/README.md b/roles/install_nextcloud/README.md index 90a32b7d..a84f6dd1 100644 --- a/roles/install_nextcloud/README.md +++ b/roles/install_nextcloud/README.md @@ -291,7 +291,7 @@ The port of redis server. Port 0 is for socket use. Default redis port is 6379. ```yaml nextcloud_redis_settings: - - { name: 'redis host', value: '"{{ nextcloud_redis_host }}"' } + - { name: 'redis host', value: "{{ nextcloud_redis_host }}" } - { name: 'redis port', value: "{{ nextcloud_redis_port }}" } - { name: 'memcache.locking', value: '\OC\Memcache\Redis' } ``` @@ -685,4 +685,4 @@ We encourage you to contribute to this role! Please check out the ## License -BSD +BSD diff --git a/roles/install_nextcloud/defaults/main.yml b/roles/install_nextcloud/defaults/main.yml index e41418fe..9e180ae2 100644 --- a/roles/install_nextcloud/defaults/main.yml +++ b/roles/install_nextcloud/defaults/main.yml @@ -62,7 +62,7 @@ nextcloud_redis_host: '/var/run/redis/redis.sock' nextcloud_redis_port: 0 nextcloud_redis_settings: - - { name: 'redis host', value: '"{{ nextcloud_redis_host }}"' } + - { name: 'redis host', value: "{{ nextcloud_redis_host }}" } - { name: 'redis port', value: "{{ nextcloud_redis_port }}" } - { name: 'memcache.locking', value: '\OC\Memcache\Redis' } diff --git a/roles/install_nextcloud/tasks/main.yml b/roles/install_nextcloud/tasks/main.yml index 505d5cdb..5240e5b5 100644 --- a/roles/install_nextcloud/tasks/main.yml +++ b/roles/install_nextcloud/tasks/main.yml @@ -92,12 +92,10 @@ - patch_user_saml_app block: - name: Lists the number of apps available in the instance - ansible.builtin.command: php occ app:list --output=json_pretty --no-warnings - args: - chdir: "{{ nextcloud_webroot }}" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + command: app:list --output=json_pretty --no-warnings + nextcloud_path: "{{ nextcloud_webroot }}" become: true - become_flags: "{{ ansible_become_flags | default(omit) }}" changed_when: false check_mode: false register: nc_apps_list @@ -116,12 +114,10 @@ - name: Add indices - ansible.builtin.command: php occ db:add-missing-indices - args: - chdir: "{{ nextcloud_webroot }}" - become_user: "{{ nextcloud_websrv_user }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: db:add-missing-indices become: true - become_flags: "{{ ansible_become_flags | default(omit) }}" register: nc_indices_cmd changed_when: '"Done" not in nc_indices_cmd.stdout' when: nextcloud_install_db diff --git a/roles/install_nextcloud/tasks/nc_installation.yml b/roles/install_nextcloud/tasks/nc_installation.yml index 746a8508..71c11f59 100644 --- a/roles/install_nextcloud/tasks/nc_installation.yml +++ b/roles/install_nextcloud/tasks/nc_installation.yml @@ -35,22 +35,19 @@ state: absent - name: nc_installation | Run occ installation command - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: > - php occ maintenance:install - --database="{{ nextcloud_tmp_backend }}" - --database-host="{{ nextcloud_db_host }}" - --database-name="{{ nextcloud_db_name }}" - --database-user="{{ nextcloud_db_admin }}" - --database-pass="{{ nextcloud_db_pwd }}" - --admin-user="{{ nextcloud_admin_name }}" - --admin-pass="{{ nextcloud_admin_pwd }}" - --data-dir="{{ nextcloud_data_dir }}" - args: - chdir: "{{ nextcloud_webroot }}" - creates: "{{ nextcloud_webroot }}/config/config.php" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: >- + maintenance:install + --database {{ nextcloud_tmp_backend }} + --database-host {{ nextcloud_db_host }} + --database-name {{ nextcloud_db_name }} + --database-user {{ nextcloud_db_admin }} + --database-pass {{ nextcloud_db_pwd }} + --admin-user {{ nextcloud_admin_name }} + --admin-pass {{ nextcloud_admin_pwd }} + --data-dir {{ nextcloud_data_dir }} vars: # mariadb is equal to mysql for occ nextcloud_tmp_backend: "{{ 'mysql' if nextcloud_db_backend == 'mariadb' else nextcloud_db_backend }}" @@ -81,48 +78,46 @@ failed_when: true - name: nc_installation | Set Trusted Domains - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: php occ config:system:set trusted_domains {{ item.0 }} --value="{{ item.1 | ansible.utils.ipwrap }}" - args: - chdir: "{{ nextcloud_webroot }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: >- + config:system:set + trusted_domains {{ item.0 }} + --value={{ item.1 | ansible.utils.ipwrap }} with_indexed_items: "{{ nextcloud_trusted_domain }}" - changed_when: true - name: nc_installation | Set Trusted Proxies - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: php occ config:system:set trusted_proxies {{ item.0 }} --value="{{ item.1 }}" - args: - chdir: "{{ nextcloud_webroot }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: >- + config:system:set + trusted_proxies {{ item.0 }} + --value={{ item.1 }} with_indexed_items: "{{ nextcloud_trusted_proxies }}" - changed_when: true - name: nc_installation | Set Nextcloud settings in config.php - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: php occ config:system:set {{ item.name }} --value="{{ item.value }}" {% if item.value | type_debug == 'bool' %}--type=boolean{% endif %} - args: - chdir: "{{ nextcloud_webroot }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: >- + config:system:set + {{ item.name }} + --value {{ item.value }}{% if item.value | type_debug == 'bool' %} --type=boolean{% endif %} with_items: - "{{ nextcloud_config_settings }}" - changed_when: true - name: nc_installation | Set Redis Server - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: php occ config:system:set {{ item.name }} --value="{{ item.value }}" {% if item.value | type_debug == 'bool' %}--type=boolean{% endif %} - args: - chdir: "{{ nextcloud_webroot }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: >- + config:system:set {{ item.name }} + --value {{ item.value }}{% if item.value | type_debug == 'bool' %} --type=boolean{% endif %} with_items: - "{{ nextcloud_redis_settings }}" when: (nextcloud_install_redis_server | bool) - register: output - changed_when: "output.rc == 0" - name: nc_installation | Configure Cron when: (nextcloud_background_cron | bool) @@ -141,15 +136,11 @@ cron_file: "nextcloud" - name: nc_installation | Set Cron method to Crontab - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" become: true - ansible.builtin.command: php occ background:cron - args: - chdir: "{{ nextcloud_webroot }}" + nextcloud.admin.run_occ: + nextcloud_path: "{{ nextcloud_webroot }}" + command: background:cron when: (nextcloud_background_cron | bool) - register: output - changed_when: "output.rc == 0" - name: nc_installation | Set Custom Mimetype ansible.builtin.copy: @@ -181,14 +172,9 @@ - updater - name: nc_installation | Disable Nextcloud apps - ansible.builtin.command: php occ app:disable "{{ item }}" - become_user: "{{ nextcloud_websrv_user }}" - become_flags: "{{ ansible_become_flags | default(omit) }}" + nextcloud.admin.app: + nextcloud_path: "{{ nextcloud_webroot }}" + state: disabled + name: "{{ item }}" become: true - register: _occ_app_disable_result - args: - chdir: "{{ nextcloud_webroot }}" - changed_when: - - "'disabled' in _occ_app_disable_result.stdout" - - "'No such app' not in _occ_app_disable_result.stdout" with_items: "{{ nextcloud_disable_apps }}"