From ad0881fddb0f9143edd515c70143fac8f103f200 Mon Sep 17 00:00:00 2001 From: Luca Matteo Spoljarevic Date: Mon, 24 Nov 2025 01:12:13 +0100 Subject: [PATCH] Playbook to create a user called master with sudo rights --- configuration/mastercreation.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 configuration/mastercreation.yml diff --git a/configuration/mastercreation.yml b/configuration/mastercreation.yml new file mode 100644 index 0000000..f192fb8 --- /dev/null +++ b/configuration/mastercreation.yml @@ -0,0 +1,39 @@ +--- +- name: Create a system user with sudo rights + hosts: all + become: true + vars: + # Use environment variables if running with e.g., GitHub Actions secrets + user_name: "{{ lookup('env', 'USR_NAME') }}" + user_pass: "{{ lookup('env', 'USR_PASS') }}" + + tasks: + - name: Ensure sudo package is installed (Debian/RHEL) + package: + name: "{{ item }}" + state: present + loop: + - sudo + become: true + + - name: Create the user + user: + name: "{{ user_name }}" + password: "{{ user_pass | password_hash('sha512') }}" + shell: /bin/bash + state: present + create_home: yes + + - name: Add user to sudoers + user: + name: "{{ user_name }}" + groups: sudo + append: yes + when: ansible_os_family == "Debian" + + - name: Add user to wheel group (RHEL/Fedora) + user: + name: "{{ user_name }}" + groups: wheel + append: yes + when: ansible_os_family == "RedHat"