While tidying up old files on my computer, I came across a PDF document: my first job ’entrance exam’ from three years ago. It was structured like an RHCSA exam, presenting real-life scenarios solved entirely through command-line tasks. Seeing this reminded me of my progress.
Inspired by this discovery, I’ve decided to revisit these exercises. However, this time, I’ll tackle them using Ansible. Here’s a snippet focusing on the user management section, as the full exam consists of 27 items.
---
- hosts: rh8-an1
tasks:
- name: Create groups
become: yes
group:
name: "{{ item }}"
loop:
- redhat
- tech
- edb
- manager
- manage
- elk
- jboss
- admin
- name: Create users with groups
become: yes
user:
name: "{{ item.name }}"
groups: "{{ item.group }}"
state: present
append: true
loop:
- { name: 'robin', group: 'redhat,tech' }
- { name: 'anthony', group: 'edb,rtm' }
- { name: 'samuel', group: 'manage,' }
- { name: 'julie', group: 'elk,rtm' }
- { name: 'wilson', group: 'jboss,rtm' }
- { name: 'sora', group: 'admin' }
- name: Create directories and change group ownership based on respective group
become: yes
file:
path: "/mnt/abc_solutions/{{ item.name }}"
group: "{{ item.group }}"
state: directory
loop:
- { name: 'redhat', group: 'redhat' }
- { name: 'edb', group: 'edb' }
- { name: 'manage', group: 'manage' }
- { name: 'elk', group: 'elk' }
- { name: 'jboss', group: 'jboss' }