master
blallo 2020-08-07 19:24:28 +02:00
commit 30f66fa488
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
3 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,24 @@
---
- name: Ensure group {{ user.group }} is present
group:
name: "{{ user.group }}"
state: present
when: user.group is defined
- name: Ensure user {{ user.username }} is present
user:
name: "{{ user.username }}"
groups:
- "{{ user.group }}"
home: "{{ user.home }}"
create_home: yes
system: no
when: user.group is defined
- name: Ensure user {{ user.username }} is present
user:
name: "{{ user.username }}"
home: "{{ user.home }}"
create_home: yes
system: no
when: user.group is not defined

12
tasks/main.yml 100644
View File

@ -0,0 +1,12 @@
---
- name: Giving access to users
include_tasks: create_user.yml
vars:
user: "{{ item }}"
with_items: "{{ share_access.users }}"
- name: Giving access to users
include_tasks: share.yml
vars:
user: "{{ item }}"
with_items: "{{ share_access.users }}"

34
tasks/share.yml 100644
View File

@ -0,0 +1,34 @@
---
- name: Ensure .ssh folder is present for user {{ user.username }}
file:
path: "{{ user.home }}/.ssh"
state: directory
owner: "{{ user.username }}"
group: "{{ user.group|default(user.username) }}"
mode: 0700
- name: Generate the keypair for user {{ user.username }}
openssh_keypair:
path: "{{ user.home }}/.ssh/key"
type: ed25519
state: present
owner: "{{ user.username }}"
group: "{{ user.group|default(user.username) }}"
mode: 0600
force: no
- name: Place key in user's authorized_keys
copy:
src: "{{ user.home }}/.ssh/key.pub"
dest: "{{ user.home }}/.ssh/authorized_keys"
remote_src: yes
owner: "{{ user.username }}"
group: "{{ user.group|default(user.username) }}"
mode: 0600
force: no
- name: Fetch private key of {{ user.username }}
fetch:
src: "{{ user.home }}/.ssh/key"
dest: "/tmp/{{ user.username }}/"
flat: yes