Update tech_docs/lab/rhcsa_lab.md

This commit is contained in:
2024-09-26 12:44:11 +00:00
parent 7f41fdad98
commit 230c33f958

View File

@@ -287,4 +287,160 @@ vagrant plugin install vagrant-libvirt
python3 --version
pip3 --version
ansible --version
```
```
---
To focus solely on **automating the base system setup** for your Rocky Linux lab, we can use **Ansible** to ensure that all necessary tools, services, and configurations are applied efficiently. This setup will automate installing dependencies, enabling services, configuring the network, and preparing the system for future use.
Heres how you can automate the entire base system setup using Ansible:
---
## **Automating the Base System Setup with Ansible**
### **Step 1: Create an Ansible Playbook for Base System Setup**
The following playbook will handle:
- System updates.
- Enabling repositories.
- Installing required packages for virtualization, development tools, and networking.
- Enabling services like **libvirt** and **firewalld**.
- Adding the user to the **libvirt** group.
---
### **Base System Setup Playbook (setup-host.yml)**
```yaml
---
- hosts: localhost
become: yes
tasks:
# Update all packages and refresh cache
- name: Update the system
dnf:
name: "*"
state: latest
update_cache: yes
# Enable CodeReady Builder (CRB) repository
- name: Enable CodeReady Builder repository
command: dnf config-manager --set-enabled crb
# Add HashiCorp repository for Vagrant
- name: Add HashiCorp repository for Vagrant
command: dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
# Refresh dnf cache
- name: Refresh dnf cache
command: dnf makecache
# Install necessary packages for virtualization, development, networking, and monitoring
- name: Install required packages
dnf:
name:
- qemu-kvm
- libvirt
- libvirt-daemon-driver-qemu
- libvirt-devel
- vagrant
- ruby-devel
- gcc
- ansible
- python3
- python3-pip
- bridge-utils
- net-tools
- wget
- curl
- vim
- git
- htop
- iotop
- iftop
- firewalld
- unzip
- kernel-devel
- kernel-headers
state: present
# Enable and start libvirt service
- name: Enable and start libvirt service
systemd:
name: libvirtd
enabled: yes
state: started
# Enable and start firewalld service
- name: Enable and start firewalld service
systemd:
name: firewalld
enabled: yes
state: started
# Add the user to the libvirt group to allow non-root VM management
- name: Add user to libvirt group
user:
name: "{{ ansible_user }}"
groups: libvirt
append: yes
```
---
### **Step 2: Run the Ansible Playbook**
1. Save the playbook to a file called `setup-host.yml`.
2. Run the Ansible playbook to automate the entire base system setup:
```bash
ansible-playbook setup-host.yml
```
---
### **Step 3: Post-Setup Instructions**
1. **Reboot the System**:
After running the playbook, its recommended to reboot the system to ensure all services start properly and the group changes take effect:
```bash
sudo reboot
```
2. **Verify Installation**:
Once the system is back online, verify that all services are enabled and working:
- Check if `libvirt` is running:
```bash
systemctl status libvirtd
```
- Check if `firewalld` is running:
```bash
systemctl status firewalld
```
- Ensure the user is added to the `libvirt` group:
```bash
groups $USER
```
---
## **What This Playbook Does**
1. **System Updates**: It ensures your system is up to date and refreshes the DNF cache.
2. **Enabling Repositories**: The playbook enables the CodeReady Builder (CRB) repository for development tools and adds the HashiCorp repository for Vagrant.
3. **Installing Required Packages**: Installs all necessary tools for virtualization (KVM, libvirt), development (GCC, Ruby), and system monitoring (htop, iotop, iftop).
4. **Enabling Services**: Automatically enables and starts key services like `libvirtd` (for VM management) and `firewalld` (for security).
5. **User Management**: Adds your user to the `libvirt` group, allowing you to manage VMs without needing root privileges.
---
## **Conclusion**
This automated base system setup ensures that your Rocky Linux environment is fully prepared for future lab deployments and VM management without manual intervention. Once the playbook is run, your system will be ready with all necessary tools and services enabled.
Let me know if you want to add any more specific features or adjustments!