FEATURE: task for creating and setting up a new user added, supplementary scripts and configs added

This commit is contained in:
2026-07-06 17:21:08 +00:00
parent 1951bf191f
commit e4089273ca
6 changed files with 236 additions and 1 deletions
@@ -0,0 +1,65 @@
---
- name: Create a new user with a password, set shell
remote_user: ansible
user:
name: max
groups: sshusers
password: "{{ user_passwd_hash }}"
shell: /bin/zsh
- name: Set authorized key taken from file
remote_user: ansible
ansible.posix.authorized_key:
user: max
state: present
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/ansible_key.pub') }}"
- name: Copy omz installation wrapper script to the target machine
remote_user: ansible
copy:
src: ../files/install_omz.sh
dest: /home/max/install_omz.sh
owner: max
group: max
mode: u=rwx,g=r,o-rwx
# WARNING: UNPRIVILEGED USER (not ansible) COMMANDS
- name: Install oh my zsh
remote_user: max
become: no
command: /home/max/install_omz.sh
- name: Configure oh my zsh, by pushing the config file
remote_user: ansible
copy:
src: ../files/.zshrc
dest: /home/max/.zshrc
owner: max
group: max
mode: u=rw,g=r,o-rwx
- name: Configure vim, by pushing the config
remote_user: ansible
copy:
src: ../files/.vimrc
dest: /home/max/.vimrc
owner: max
group: max
mode: u=rw,g=r,o-rwx
# WARNING: we've finished with the initial setup, drop ansible key
# Push regular user key
- name: Set authorized key taken from file
remote_user: ansible
ansible.posix.authorized_key:
user: max
state: absent
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/ansible_key.pub') }}"
- name: Set authorized key taken from file
remote_user: ansible
ansible.posix.authorized_key:
user: max
state: present
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/max_regular_key.pub') }}"
+4 -1
View File
@@ -6,4 +6,7 @@
ansible.builtin.include_tasks: harden_ssh.yaml
- name: Install basic utils
ansible.builtin.include_tasks: install_basic_utils.yaml
ansible.builtin.include_tasks: install_basic_utils.yaml
- name: Create and set up a new user
ansible.builtin.include_tasks: create_new_user.yaml
@@ -0,0 +1,27 @@
---
# Remove multiple packages at once
- name: Remove unnecessary packages
remote_user: ansible
when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu")
apt:
name:
- nano
state: absent
become: yes
# Clean up all orphaned packages
- name: Remove all orphaned dependencies
remote_user: ansible
when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu")
apt:
autoremove: yes
purge: yes
- name: Install sudo package on Alpine
remote_user: ansible
when: (ansible_facts['distribution'] == "Alpine")
command: /sbin/apk del nano