Infra/ansible/tasks/users.yml

29 lines
1.0 KiB
YAML
Raw Normal View History

2021-08-16 23:50:14 +02:00
- name: Ensure groups exists
2022-10-19 00:18:29 +02:00
when: "inventory_hostname not in groups['prox']"
2021-08-16 23:50:14 +02:00
ansible.builtin.group:
2022-04-15 15:51:58 +02:00
name: "{{ user.groupname | default(user.username) }}"
gid: "{{ user.gid | default(omit) }}"
2021-08-16 23:50:14 +02:00
state: present
- name: Add users
2022-10-19 00:18:29 +02:00
when: "inventory_hostname not in groups['prox']"
2021-08-16 23:50:14 +02:00
ansible.builtin.user:
name: "{{ user.username }}"
2022-04-15 15:51:58 +02:00
uid: "{{ user.uid | default(omit) }}"
2021-08-16 23:50:14 +02:00
group: "{{ user.groupname | default(user.username) }}"
shell: "{{ user.shell | default('/bin/bash') }}"
2022-04-15 15:51:58 +02:00
move_home: "{{ user.home | default(omit) }}"
password: "{{ user.password | password_hash('sha512') | default(omit) }}"
2021-08-16 23:50:14 +02:00
- name: Add a Github key ssh key
2022-10-19 00:18:29 +02:00
when: "user.github is defined and inventory_hostname not in groups['prox']"
2021-08-16 23:50:14 +02:00
ansible.posix.authorized_key:
user: "{{ user.username }}"
key: "https://github.com/{{ user.github }}.keys"
2022-10-19 00:18:29 +02:00
- name: Add a Github key ssh key
when: inventory_hostname in groups['prox']
ansible.posix.authorized_key:
user: root
key: "https://github.com/{{ user.github }}.keys"