2020-11-13 03:02:41 +00:00
|
|
|
---
|
|
|
|
# create user and group
|
|
|
|
|
|
|
|
- name: "Ensure group {{ group_name }} exists"
|
|
|
|
become: yes
|
|
|
|
group:
|
|
|
|
name: "{{ group_name }}"
|
|
|
|
|
|
|
|
- name: "create {{ user_name }} user and {{ group_name }} group"
|
|
|
|
become: yes
|
|
|
|
user:
|
|
|
|
name: "{{ user_name }}"
|
|
|
|
comment: "Login user generate by ansible"
|
2021-01-13 22:39:48 +00:00
|
|
|
shell: /bin/bash
|
2020-11-13 03:02:41 +00:00
|
|
|
groups:
|
|
|
|
- debian
|
|
|
|
- "{{ group_name }}"
|
|
|
|
|
|
|
|
- name: "create directory .ssh for public key"
|
|
|
|
become: yes
|
|
|
|
file:
|
|
|
|
path: "/home/{{ user_name }}/.ssh"
|
|
|
|
owner: "{{ user_name }}"
|
|
|
|
group: "{{ group_name }}"
|
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
when: ssh_public_key is defined and ssh_public_key != ""
|
|
|
|
|
|
|
|
- name: "setup ssh key"
|
|
|
|
become: yes
|
|
|
|
copy:
|
|
|
|
content: "{{ ssh_public_key }}"
|
|
|
|
dest: "/home/{{ user_name }}/.ssh/authorized_keys"
|
|
|
|
owner: "{{ user_name }}"
|
|
|
|
group: "{{ group_name }}"
|
|
|
|
when: ssh_public_key is defined and ssh_public_key != ""
|