52 lines
1.3 KiB
YAML
52 lines
1.3 KiB
YAML
---
|
|
|
|
- name: Get user list
|
|
command: php occ user:list --output=json
|
|
args:
|
|
chdir: "{{ nextcloud_installation_dir }}"
|
|
register: nextcloud_online_users
|
|
changed_when: false
|
|
become: true
|
|
become_user: "{{ nextcloud_file_owner }}"
|
|
|
|
# There might be non-json lines that break parsing.
|
|
- name: Remove non-json text from command output
|
|
set_fact:
|
|
nextcloud_online_users: >-
|
|
{{
|
|
(
|
|
nextcloud_online_users.stdout
|
|
| regex_replace('^[^{]*(.*)$', '\1')
|
|
| from_json
|
|
).keys()
|
|
| list
|
|
}}
|
|
|
|
- name: Create users
|
|
command: >-
|
|
php occ user:add
|
|
"{{ item.name }}"
|
|
--display-name "{{ item.display_name }}"
|
|
--password-from-env
|
|
args:
|
|
chdir: "{{ nextcloud_installation_dir }}"
|
|
when: item.name not in nextcloud_online_users
|
|
environment:
|
|
OC_PASS: "{{ item.pass }}"
|
|
loop: "{{ nextcloud_users }}"
|
|
become: true
|
|
become_user: "{{ nextcloud_file_owner }}"
|
|
|
|
- name: Update user password
|
|
command: php occ user:resetpassword "{{ item.name }}" --password-from-env
|
|
args:
|
|
chdir: "{{ nextcloud_installation_dir }}"
|
|
when:
|
|
- item.resetpassword | default(False)
|
|
- item.name in nextcloud_online_users
|
|
environment:
|
|
OC_PASS: "{{ item.pass }}"
|
|
loop: "{{ nextcloud_users }}"
|
|
become: true
|
|
become_user: "{{ nextcloud_file_owner }}"
|