- name: Set user configuration
  block:
    - name: Set admin username fact
      ansible.builtin.set_fact:
        user_name: "{{ admin_user_name }}"
        user_home: "/home/{{ admin_user_name }}"
      delegate_to: localhost
      run_once: true

- name: User Creation and Sudo Configuration
  block:
    - name: Create new user and set shell for '{{ user_name }}'
      ansible.builtin.user:
        name: "{{ user_name }}"
        state: present
        shell: /usr/bin/bash

    - name: Add to sudo group new user '{{ user_name }}'
      ansible.builtin.user:
        name: "{{ user_name }}"
        groups: [sudo]
        append: true

    - name: Configure sudoers (NOPASSWD) for '{{ user_name }}'
      ansible.builtin.lineinfile:
        path: /etc/sudoers.d/010_sudo_user
        line: "{{ user_name }} ALL=(ALL) NOPASSWD: ALL"
        create: true
        mode: "0440"
        validate: "/usr/sbin/visudo -cf %s"
