Update create_user_ssh/main.yml

This commit is contained in:
David Lopez 2023-07-25 12:29:29 +00:00
parent 974f5b71b7
commit 1d62c23490
1 changed files with 19 additions and 40 deletions

View File

@ -1,40 +1,19 @@
--- - name: Create New User
- name: Add user | Debian based OS hosts: all
user: become: true
name: "{{ username }}" gather_facts: false
groups: sudo,shadow vars:
shell: /bin/bash # Define your username and password here that you want to create on target hosts.
append: yes username: hola
generate_ssh_key: yes userpass: password
ssh_key_bits: 4096 supergroup: sudoers
ssh_key_file: .ssh/id_rsa tasks:
when: ansible_os_family == "Debian" - name: Create User
ansible.builtin.user:
- name: Add user | Redhat based OS name: "{{ username }}"
user: state: present
name: "{{ username }}" shell: /bin/bash
groups: wheel password: "{{ userpass | password_hash('sha512') }}"
shell: /bin/bash update_password: on_create
append: yes groups: "{{ super_group }}"
generate_ssh_key: yes append: yes
ssh_key_bits: 4096
ssh_key_file: .ssh/id_rsa
when: ansible_os_family == "RedHat"
- name: Sudo | add to sudoers file and validate
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^{{ username }} '
# line: '{{username}} ALL=(ALL) NOPASSWD:ALL'
line: "{{ username }} ALL=(ALL) {{ 'NOPASSWD:' if ( default_sudo_nopass|d(true)|bool ) else '' }}ALL"
validate: 'visudo -cf %s'
environment:
PATH: /usr/sbin:/usr/local/sbin:/sbin
#environment fixes Redhat issue of hard-coded path to visudo
- name: SSH Keys | Add authorized key for ssh key authentication
authorized_key:
user: "{{ username }}"
state: present
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"