Skip to content

Commit

Permalink
Merge pull request #370 from nextcloud/use_occ_module
Browse files Browse the repository at this point in the history
Replace usage of command module with run_occ module in collection's roles
  • Loading branch information
aalaesar authored Sep 12, 2024
2 parents 2a887bd + 68108b3 commit 1fc1400
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 3 additions & 4 deletions roles/backup/tasks/finishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions roles/backup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 30 additions & 28 deletions roles/backup/tasks/nc_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,32 +28,29 @@
- 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
ansible.builtin.set_fact:
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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions roles/install_nextcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
```
Expand Down Expand Up @@ -685,4 +685,4 @@ We encourage you to contribute to this role! Please check out the
## License
BSD
BSD
2 changes: 1 addition & 1 deletion roles/install_nextcloud/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down
16 changes: 6 additions & 10 deletions roles/install_nextcloud/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
98 changes: 42 additions & 56 deletions roles/install_nextcloud/tasks/nc_installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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 }}"

0 comments on commit 1fc1400

Please sign in to comment.