Files
Kamino/roles/network_interfaces/README.md
T
Defame1297andClaude Sonnet 5.5 cf8f4b5bf0
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 17s
Molecule / molecule (pull_request) Successful in 4m43s
feat(roles): add the systemd_hardening and network_interfaces roles
Copied from the environment repository's roles and scrubbed for the
Collection: galaxy namespace mortis, molecule scenarios call the roles by
their FQCN and take their paths from the workflow, README examples use
mortis.kamino.* and documentation addresses, repository-local references
(issue numbers, ADRs, inventory paths) are dropped. network_interfaces
loses its Legacy name guard and the molecule play that tested it: the
guard only protected the in-repo rename, and a new consumer never had the
old names. mock_roles in .ansible-lint lists both FQCNs.

Not verified locally: the molecule scenarios (they run on the
kamino-molecule runner in CI) and ansible-test sanity.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-10 15:09:48 +00:00

61 lines
3.5 KiB
Markdown

# network_interfaces
Renders `/etc/network/interfaces` from a list of manual interfaces and bridges, validates it with `ifreload`, and restores the backup if validation fails. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
## Supported platforms
Debian-based hosts using `ifupdown2` (`ifreload`), such as Proxmox hosts. The molecule scenario (`molecule/default/`, CI only) runs on Ubuntu 24.04 without `ifupdown2`: the validate and reload commands are stubs, so it tests the rendered file, the backup, the single reload and the restore after a failing validation. It does not test `ifreload`, so no Debian release or `ifupdown2` version is verified by a test.
## Requirements and run order
- `ifupdown2` must be installed, because the validate and apply commands call `ifreload`.
- Use it by its fully qualified name, `mortis.kamino.network_interfaces`.
- Run it with `serial: 1` and the most important host last, so a bad change is caught on another host first. It rewrites the host's network configuration, so run it before roles that depend on the network.
- Gathered facts are not read. The tasks use `become` where they write.
- `network_interfaces_layout` normally comes from inventory (group_vars or host_vars), so each host can have its own layout.
## Role variables
| Variable | Default | Required | Description |
|---|---|---|---|
| `network_interfaces_layout` | `manual: []`, `bridges: []` | no | `manual` is a list of interface names. `bridges` is a list of mappings with `name`, `method`, `address`, `netmask`, `gateway`, `ports`, `stp`, `fd`, `vlan_aware`, `vlan_ids`. |
| `network_interfaces_file` | `/etc/network/interfaces` | no | File rewritten. |
| `network_interfaces_backup` | `/etc/network/interfaces.bak` | no | Backup path. |
| `network_interfaces_validate_command` | `ifreload -s -a` | no | Validation command. |
| `network_interfaces_apply_command` | `ifreload -a` | no | Reload command, run by the handler. |
The `address` sub-option is typed `raw` in the spec so that an inventory can template it, for example from `ansible_host`.
## Tags
None. The role does not tag its tasks, so only a play-level tag applies.
## Example play
```yaml
- hosts: hypervisors
serial: 1
roles:
- role: mortis.kamino.network_interfaces
vars:
network_interfaces_layout:
manual: [nic0, nic1]
bridges:
- name: vmbr0
method: static
address: 192.0.2.10
netmask: 255.255.255.0
gateway: 192.0.2.1
ports: nic0
vlan_aware: true
```
## Notes
- The template replaces the whole file: any stanza not described by `network_interfaces_layout` is dropped. Interfaces carried by other consumers (for example a bridge that carries a router VM's WAN) must be listed.
- Only a content difference triggers work. Idempotent runs change nothing.
- On change the order is: copy the current file to `network_interfaces_backup`, write the new file (notifies `Reload Interfaces`), run the validate command, flush handlers. Any failure in that block restores the backup and fails with "Invalid network configuration detected. Previous config restored." The restore does not reload the interfaces.
- The validate command runs after the file is written, and the reload runs right after it. A configuration that passes validation but breaks connectivity is not detected.
- With `method: static`, `address` and `netmask` are required by the template.
- `no_log` is not used: the role handles no secrets.