LFCA 2.2: Best practices
Turning off a service nobody needs, a runbook, a script for a manual task, and a first Ansible playbook.
Before you start
Work as root (sudo -i), so ~ is /root. The lab starts a service this
VM doesn't need, listening on TCP port 7070, and creates group
developers. It notes whether nginx and Ansible are installed, and reset
puts that back. The VM needs internet access to install packages.
Tasks
- Check which services listen on the network with
ss -tulpn. Find the one on port 7070, which this VM doesn't need, and turn it off now and at boot. - Write a runbook for restarting nginx and checking it came back, then have someone else follow it. Not graded.
- Turn a three-step manual task into a shell script: write
/root/add-dev.shthat takes a user name, creates that user, adds them to groupdevelopers, and creates a directory/srv/NAMEthey own. Make it executable and run it for usererin. - Install Ansible (the
ansiblepackage on Ubuntu,ansible-coreon the RHEL family). In/root/ansible, make an inventory fileinventorywith a[webservers]line followed bylocalhost ansible_connection=local, and save the chapter's nginx playbook asplaybook.yml. Run it against the VM withansible-playbook -i inventory -K playbook.yml, twice, and compare the output.
Hints
ss -tulpnshows the process;systemctl status PIDshows its unit.systemctl disable --now UNIT.#!/bin/bashfirst,$1is the name;useradd -m,usermod -aG(oruseradd -G),mkdir,chown;chmod +x.dnf install ansible-core/apt install ansible. The playbook'shosts: webserversmatches the inventory's group;-Kasks for the sudo password (as root, just press Enter). The second run should showchanged=0.