Linux systems base settings.
Running roles in containers is not common, but this use case is supported for Ansible testing with Molecule. When it detects a container, the role leaves to the container engine what belongs to it : host names, firewall, clock, sudo, sshd and reboots are not managed. Everything else still applies — package managers, packages, users, CA certificates.
GitLab project: yoanncolin/ansible/roles/system
This role has been written to be run as a non root user, so Sudo has to be installed and configured. It requires ansible-core 2.19 or above.
It uses the ansible.posix,
ansible.utils and community.general
collections. Installing the role does not install them: they are listed in the
requirements.yml shipped with it.
ansible-galaxy collection install -r requirements.ymlOn the controller, the role needs the jmespath Python package,
and network configuration the netaddr one too.
Defined facts of this role :
system_boot_modesystem_kernelsystem_mountssystem_needs_rebootsystem_packagessystem_servicessystem_shellssystem_uptime
Look at the facts documentation for more details.
Some values are dispatched in multiple tasks, so You can quickly update them with tags :
ca- SSL certificates authoritiesfirewallhosts- Update/etc/hostsfilenetworkspackage-managerspackagesproxiesremote-accesssshstoragessudoerstimeusers
Usage :
ansible-playbook -t tag1[,tag2[,...]] my_play.yml--check --diff shows what the role would change on a host and changes
nothing. Commands that only look at the host still run — the reboot detection,
the age of the package index, the Portage profile in use — so what the role
reports rests on the host's real state. Commands that act, a Portage sync or
the cleanup of old kernels for instance, are skipped.
System components are managed through separated tasks that could be called independently.
Of course, all tasks are called in the
- facts
- proxies
- hosts
- packages
- modules
- networks
- storages
- sudo
- users
- zsh
- ca
- time
- firewall
- remote-access
- reboots
Look at defaults/main/feature-flipping.yml.
Enable/disable some features by setting them to true/false.
Some tasks may depend on another one. For example, storage and network management may require the installation of packages, but packages are fetched through the network and stored on disk.
You can change the installation sequence for your specific situation
defining the system_sequence variable.
Here is the default sequence :
system_sequence:
- modules
- proxies
- hosts
- sudo
- package-managers
- packages
- networks
- storages
- users
- ca
- time
- firewall
- remote-accessNote that the facts task is implicitly called by the other tasks if needed.
Look at defaults/main/common.yml.
system_scripts_path: /usr/local/bin
system_profile: serverSome tasks of this role need to put scripts. They are stored in the
system_scripts_path directory.
The system_profile can impact the behaviour of some parts of the system,
for example the packages to install (or not). It is a / separated path,
each segment adding to the ones before it :
| Segment | What it adds |
|---|---|
server |
nothing of its own — the default |
desktop |
LibreOffice, Firefox and usbutils, plus the Yay AUR helper on ArchLinux |
gnome |
the GNOME session, its utilities and the gdm service |
hardened |
a hardened sshd configuration, replacing the distribution one |
Whatever the profile, every node gets acl, sudo and rsync. The usual
combinations :
system_profile: server # the default
system_profile: server/hardened
system_profile: desktop
system_profile: desktop/gnome
system_profile: desktop/gnome/hardenedA segment naming none of the profiles above brings nothing. It is ignored, and said so in the play output rather than dropped silently :
TASK [gwerlas.system : Facts - Report unknown system_profile segments] *****
[WARNING]: [node] system_profile segment(s) gnom match no known profile and
are ignored (available: desktop, gnome, hardened, server)
ok: [node]
A reachable Linux system with Python installed.
First deployment or distribution upgrade, 10 steps rolling update :
---
- name: Rolling update
hosts: all
serial: 10%
roles:
- role: gwerlas.system
vars:
system_packages_upgrade: trueUsing just one task :
---
- name: Package managers
hosts: all
tasks:
- name: Just get the package manager upready
ansible.builtin.import_role:
name: gwerlas.system
tasks_from: package-managers