From 1d62c23490ba8ed7fc423b31221b616de5d200f0 Mon Sep 17 00:00:00 2001 From: David Lopez Date: Tue, 25 Jul 2023 12:29:29 +0000 Subject: [PATCH] Update create_user_ssh/main.yml --- create_user_ssh/main.yml | 59 +++++++++++++--------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/create_user_ssh/main.yml b/create_user_ssh/main.yml index 17e3538..a37843a 100644 --- a/create_user_ssh/main.yml +++ b/create_user_ssh/main.yml @@ -1,40 +1,19 @@ ---- -- name: Add user | Debian based OS - user: - name: "{{ username }}" - groups: sudo,shadow - shell: /bin/bash - append: yes - generate_ssh_key: yes - ssh_key_bits: 4096 - ssh_key_file: .ssh/id_rsa - when: ansible_os_family == "Debian" - -- name: Add user | Redhat based OS - user: - name: "{{ username }}" - groups: wheel - shell: /bin/bash - append: yes - generate_ssh_key: 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') }}" \ No newline at end of file +- name: Create New User + hosts: all + become: true + gather_facts: false + vars: +# Define your username and password here that you want to create on target hosts. + username: hola + userpass: password + supergroup: sudoers + tasks: + - name: Create User + ansible.builtin.user: + name: "{{ username }}" + state: present + shell: /bin/bash + password: "{{ userpass | password_hash('sha512') }}" + update_password: on_create + groups: "{{ super_group }}" + append: yes