ansible/roles/vm-common/tasks/users.yml

26 lines
695 B
YAML
Raw Normal View History

# vim: ft=yaml.ansible
2024-03-01 20:30:18 +00:00
# code: language=ansible
2018-05-08 19:09:24 +00:00
---
2018-05-08 19:31:12 +00:00
- name: "Add users"
2018-05-08 19:09:24 +00:00
user:
name: "{{ item.name }}"
comment: "{{ item.comment }}"
password: "{{ item.password }}"
groups: "{{ item.groups }}"
2023-10-04 19:44:37 +00:00
update_password: always
shell: /bin/bash
loop: "{{ users | default([]) }}"
2018-05-08 19:09:24 +00:00
- name: "Add ssh authorized_keys"
ansible.posix.authorized_key:
user: "{{ item.name }}"
key: "{{ item.ssh_keys | join('\n') }}"
exclusive: true
loop: "{{ users | default([]) }}"
- name: "Add ssh authorized_keys to root user"
ansible.posix.authorized_key:
user: "root"
2022-11-16 15:24:22 +00:00
key: "{{ users | default([]) | map(attribute='ssh_keys') | flatten | join('\n') }}"
exclusive: true