# Collection: ansible.samuliy

[![builds.sr.ht status](https://builds.sr.ht/~samuliy/ansible.svg)](https://builds.sr.ht/~samuliy/ansible?)

## Description

Ansible roles and playbooks for home desktop and server management.

Mainly targeted at Gentoo (with systemd), Debian and OpenWrt hosts, with varying support for each distribution between roles.

## Usage

Install the collection.

```bash
ansible-galaxy collection install samuliy.ansible
```

Using a role in a playbook:

```yaml
- name: Play
  hosts:
    - all
  roles:
    - samuliy.ansible.<ROLE_NAME>
```

### Running the playbooks

Clone the repo.

Run: `ansible-galaxy collection install -r requirements.yml`

Add values for environment variables:
- `ANSIBLE_VAULT_PASSWORD` - fetched via script bin/ansible-get-vault-password
- `ANSIBLE_BECOME_PASSWORD` - fetched via script bin/ansible-get-become-password
- `ANSIBLE_INVENTORY`

Create an inventory. Targeted groups:
- gentoo
- debian
- openwrt
- linux
- systemd
- etc... look into the playbooks to find out.

Run the main playbook: `ansible-playbook playbook.yml`

Update host packages, containers, etc.: `ansible-playbook playbook-update.yml`

Run cleanup tasks: `ansible-playbook playbook-clean.yml`

## Playbooks

This project includes various playbooks that combine the roles for managing different types of hosts.

### Main entrypoint: playbook.yml

Main playbook. Prepares, installs and configures the systems.

#### playbook-main.yml

Main phase playbook which gathers all the essential playbooks and tasks into one.

#### playbook-secondary.yml

Secondary phase playbook which gathers the less important playbooks and tasks into one.

#### playbook-connect.yml

Makes sure connection can be made and waits for host boot to be done.

#### playbook-gather-facts.yml

Prepares the inventory and the groups.

#### playbook-setup.yml

Runs tasks required for the host, required to happen before other tasks.

#### playbook-self-signed-certificates.yml

For generating and propagating self-signed certificates.

#### playbook-setup-debian.yml

Runs tasks required for Debian hosts, required to happen before other tasks.

#### playbook-setup-gentoo.yml

Runs tasks required for Gentoo hosts, required to happen before other tasks.

#### playbook-setup-systemd.yml

Runs tasks required for hosts running systemd, required to happen before other tasks.

#### playbook-local-network.yml

Prepares the hosts for being available on local network.

#### playbook-hardware.yml

Sets up the hardware configuration on the host.

#### playbook-hardware.yml

Sets up the locale configuration on the host.

#### playbook-gentoo.yml

Tasks and roles for Gentoo systems.

#### playbook-debian.yml

Tasks and roles for Debian systems.

#### playbook-openwrt.yml

Tasks and roles for OpenWrt systems.

#### playbook-termux.yml

For mobile devices that run Termux.

#### playbook-systemd.yml

For Linux systems that run systemd.

#### playbook-linux.yml

For generic Linux hosts.

#### playbook-local-network.yml

Prepares the hosts for being available on public network.

#### playbook-certificates.yml

For configuring certificates.

#### playbook-git.yml

For setting up git and git repos.

#### playbook-backup.yml

For setting up backups.

#### playbook-metrics.yml

Tasks and roles for installing metrics and monitoring related software.

#### playbook-observability.yml

Tasks and roles for viewing metrics.

#### playbook-kde.yml

For desktops that run KDE.

#### playbook-printer.yml

Tasks and roles for printers.

#### playbook-docker.yml

Tasks and roles for hosts that run Docker daemon and containers.

#### playbook-podman.yml

For hosts that require Podman.

#### playbook-bluesky-pds.yml

For hosts that run a Bluesky PDS.

#### playbook-finalize.yml

Playbook for last things to do after everything else is done.

#### playbook-finalize-systemd.yml

Playbook for systemd hosts for last things to do after everything else is done.

#### playbook-devsec-hardening.yml

For running devsec hardening roles.

#### playbook-suspend.yml

Suspend hosts that do not need to be up after running the playbooks.

### Updating systems: playbook-update.yml

Playbook for updating the systems. Updates packages, containers etc.

Runs the `playbook-update-*.yml` playbooks.

### Upgrading systems: playbook-upgrade.yml

Playbook for doing full system upgrades, such as sysupgrade for an OpenWrt router.

### Cleaning up: playbook-clean.yml

Playbook for cleaning after updates. Removes unneeded packages, old files, etc.

### WOL: playbook-wol.yml

Playbook for waking up hosts that support Wake-On-Lan.

## Tests

Test can be run locally or with `podman`. Run with `make test`.

When running `make test`, test logs are redirected and can be found under `testlogs` directory in project root directory.

Podman test wrappers can be found under `/bin`.

Molecule tests are not configured to provision a run environment and are run on localhost unless a `podman` wrapper is used.

Create new tests by running `bin/dev-molecule-test <ROLE_NAME>`.
