1
0
Fork 0
ynh-lydra-ansible-yunohost/tasks/users.yml
Arthur BOUDREAULT c23177170e ♻refactor: Command ansible module across the repo for better security
Shell module is not needed here.

According to various sources (https://www.youtube.com/watch?v=57gAqKvAKck or https://stackoverflow.com/questions/56663332/difference-between-shell-and-command-in-ansible) it is not useful to use shell ansible module when not working with operands. Therefore I have decided to switch every actions to command module, more secure. Ansible-lint says "Shell should only be used when piping, redirecting or chaining commands"
2021-10-12 14:00:56 +00:00

18 lines
594 B
YAML

---
- name: List users
ansible.builtin.command: yunohost user list --output-as json
register: ynh_registered_users_raw
changed_when: False
- name: Format json of users
ansible.builtin.set_fact: ynh_registered_users="{{ ynh_registered_users_raw.stdout | from_json }}"
- name: Create missing Yunohost users
ansible.builtin.command:
yunohost user create "{{ item.name }}" \
-f "{{ item.firstname }}" \
-l "{{ item.lastname }}" \
-d "{{ item.mail_domain }}" \
-p "{{ item.pass }}"
loop: "{{ ynh_users }}"
when: item.name not in ynh_registered_users.users.keys()