Playbook para adicionar e gerenciar usuarios no Linux
Gerando senha criptografada
Gerando chaves ssh-key por usuario
$ ssh-keygen -t rsa -b 2048 -v -f keyname
Arquivo de inventario para adicionar novos hosts
Playbook: deploy-user.yml
---
- hosts : linux-servers
become : true
become_user : root
gather_facts : false
tasks :
- name : Criando usuario remoto
user :
name : remoto
comment : Usuario padrao de acesso remoto SSH
groups : wheel
shell : /bin/bash
password : $1$2cn8rY.D$VBMDKK6JqViPMyjUNPIib/
tags : user
- name : Setando chave ssh key
authorized_key :
user : remoto
state : present
key : " {{ lookup('file', 'remoto.pub') }}"
tags : ssh-key
- name : Copiando file sudoers
copy :
src : sudoers
dest : /etc/sudoers
owner : root
group : root
mode : 0444
tags : sudo
- name : Padrinozando senha de root
user :
name : root
password : $1$2cn8rY.D$VBMDKK6JqViPMyjUNPIib/
tags : user
- name : Setando chaves ssh key
authorized_key :
user : root
state : present
key : " {{ lookup('file', 'ansible.pub') }}"
tags : ssh-key
ansible-playbook -i inventory deploy-user.yml -k -u root