ansible/roles/nextcloud/tasks/users/user.yml
Salt 11d0cad9fb Add Nextcloud
AND BOY DOES IT SMELL
2020-11-01 04:55:05 -06:00

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 }}"