Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
318229bdb3 | ||
|
|
6f73021d3f | ||
|
|
9d365f14ae | ||
|
|
44cd287d41 | ||
|
|
8def6cf274 | ||
|
|
da76e995b6 | ||
|
|
0d0fc3d1ec | ||
|
|
87b87dbcef | ||
|
|
efd3a550c5 | ||
|
|
5364f18728 | ||
|
|
62ffae7764 | ||
|
|
392fbd910b | ||
|
|
f55fe7cf72 | ||
|
|
5aa27d2727 | ||
|
|
3bfc485076 | ||
|
|
3bc21bd630 | ||
|
|
69576a4dd7 | ||
|
|
3149c22f93 | ||
|
|
887302b208 | ||
|
|
ebac95e51d | ||
|
|
428b88a822 | ||
|
|
0a5a5c532a | ||
|
|
8c00be1af2 | ||
|
|
a9a332457b | ||
|
|
1bbf3368ee | ||
|
|
910d79768a | ||
|
|
d167cbefc5 | ||
|
|
71ae86dc61 | ||
|
|
d84fb4a2f4 | ||
|
|
9979dfa8ed | ||
|
|
bf6f9b5800 | ||
|
|
66628635b9 |
No files matched your search
@@ -62,7 +62,7 @@ jobs:
|
||||
# The same for Ubuntu 26.04, the release the hosts are moving to; used by
|
||||
# `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604.
|
||||
MOLECULE_IMAGE_2604: >-
|
||||
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.6@sha256:d7c216b33d18fa8f1ecbfee8795eb4adc867fe5ad8e7a73b7c67effe301cf771
|
||||
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.7@sha256:86ee99fe77ab4c9af3911570ae7238ce525375cfaf923e9656860606c47488df
|
||||
# Names and labels this run's containers: the scenarios' as `${KAMINO_RUN_ID:-local}-<name>`
|
||||
# with the label net.rkdr.mortis.molecule-run, and the one molecule runs in.
|
||||
KAMINO_RUN_ID: ${{ github.run_id }}-${{ github.run_attempt }}
|
||||
|
||||
@@ -4,6 +4,21 @@ mortis.kamino Release Notes
|
||||
|
||||
.. contents:: Topics
|
||||
|
||||
v2.1.0
|
||||
======
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- docker - Add ``docker_daemon_options``, ``docker_live_restore``, ``docker_log_driver``, ``docker_log_max_size``, ``docker_log_max_file`` and ``docker_daemon_restart``, which manage ``/etc/docker/daemon.json``. The file is written, before the packages are installed, only when at least one of the first five is set, so a host that sets none is unchanged; the role then owns the whole file. It restarts dockerd only when ``docker_daemon_restart`` is true (default ``false``), because a restart with ``live-restore`` off ends every container, and says that the file applies at the next restart otherwise. A key that ``docker_daemon_options`` and a dedicated input both set, a bad ``docker_log_driver``, ``docker_log_max_size`` or ``docker_log_max_file`` stops the run before any change.
|
||||
- pihole - New role. Installs Pi-hole v6 on Ubuntu noble by cloning the upstream repository and running its installer unattended, with ``pihole.toml`` rendered from ``pihole_default`` merged with ``pihole_overrides``. ``pihole_web_password`` is a required secret input, and ``pihole_overrides`` must set ``config.dns.interface``. A change to ``pihole.toml`` runs the installer's reconfigure mode. Derived from codeberg.org/ansible/pihole (GPL-3.0-only), with Pi-hole FTL comment text (EUPL-1.2).
|
||||
- system_baseline - add ``system_baseline_apt_tmpdir`` (default ``/var/cache/system-baseline-apt-tmp``), the directory the apt upgrade and autoremove use as ``TMPDIR``. The role creates it (root, mode ``0700``) when it runs the ``update`` flow, including the ``update`` entry point, and refuses a value under ``/tmp`` or ``/var/tmp``, a relative path or a ``..``.
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- system_baseline - the apt upgrade no longer loses its staged packages when it upgrades ``openssh-server`` on a host whose ``ssh.service`` has ``PrivateTmp=yes``. The restart of that unit deleted ``/tmp`` and ``/var/tmp`` in the middle of the upgrade, so dpkg failed with "cannot access archive" and left packages unpacked but not configured. The upgrade and the autoremove now run with ``TMPDIR`` set to ``system_baseline_apt_tmpdir``, and the role opens a new connection afterwards.
|
||||
|
||||
v2.0.1
|
||||
======
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
||||
EUPL © the European Union 2007, 2016
|
||||
|
||||
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the
|
||||
terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such
|
||||
use is covered by a right of the copyright holder of the Work).
|
||||
The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following
|
||||
notice immediately following the copyright notice for the Work:
|
||||
Licensed under the EUPL
|
||||
or has expressed by any other means his willingness to license under the EUPL.
|
||||
|
||||
1.Definitions
|
||||
In this Licence, the following terms have the following meaning:
|
||||
— ‘The Licence’:this Licence.
|
||||
— ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available
|
||||
as Source Code and also as Executable Code as the case may be.
|
||||
— ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or
|
||||
modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work
|
||||
required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in
|
||||
the country mentioned in Article 15.
|
||||
— ‘The Work’:the Original Work or its Derivative Works.
|
||||
— ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and
|
||||
modify.
|
||||
— ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by
|
||||
a computer as a program.
|
||||
— ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence.
|
||||
— ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to
|
||||
the creation of a Derivative Work.
|
||||
— ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the
|
||||
Licence.
|
||||
— ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating,
|
||||
transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential
|
||||
functionalities at the disposal of any other natural or legal person.
|
||||
|
||||
2.Scope of the rights granted by the Licence
|
||||
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for
|
||||
the duration of copyright vested in the Original Work:
|
||||
— use the Work in any circumstance and for all usage,
|
||||
— reproduce the Work,
|
||||
— modify the Work, and make Derivative Works based upon the Work,
|
||||
— communicate to the public, including the right to make available or display the Work or copies thereof to the public
|
||||
and perform publicly, as the case may be, the Work,
|
||||
— distribute the Work or copies thereof,
|
||||
— lend and rent the Work or copies thereof,
|
||||
— sublicense rights in the Work or copies thereof.
|
||||
Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the
|
||||
applicable law permits so.
|
||||
In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed
|
||||
by law in order to make effective the licence of the economic rights here above listed.
|
||||
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the
|
||||
extent necessary to make use of the rights granted on the Work under this Licence.
|
||||
|
||||
3.Communication of the Source Code
|
||||
The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as
|
||||
Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with
|
||||
each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to
|
||||
the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to
|
||||
distribute or communicate the Work.
|
||||
|
||||
4.Limitations on copyright
|
||||
Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the
|
||||
exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations
|
||||
thereto.
|
||||
|
||||
5.Obligations of the Licensee
|
||||
The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those
|
||||
obligations are the following:
|
||||
|
||||
Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to
|
||||
the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the
|
||||
Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work
|
||||
to carry prominent notices stating that the Work has been modified and the date of modification.
|
||||
|
||||
Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this
|
||||
Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless
|
||||
the Original Work is expressly distributed only under this version of the Licence — for example by communicating
|
||||
‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the
|
||||
Work or Derivative Work that alter or restrict the terms of the Licence.
|
||||
|
||||
Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both
|
||||
the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done
|
||||
under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed
|
||||
in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with
|
||||
his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
|
||||
|
||||
Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide
|
||||
a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available
|
||||
for as long as the Licensee continues to distribute or communicate the Work.
|
||||
Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names
|
||||
of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the copyright notice.
|
||||
|
||||
6.Chain of Authorship
|
||||
The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or
|
||||
licensed to him/her and that he/she has the power and authority to grant the Licence.
|
||||
Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or
|
||||
licensed to him/her and that he/she has the power and authority to grant the Licence.
|
||||
Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions
|
||||
to the Work, under the terms of this Licence.
|
||||
|
||||
7.Disclaimer of Warranty
|
||||
The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work
|
||||
and may therefore contain defects or ‘bugs’ inherent to this type of development.
|
||||
For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind
|
||||
concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or
|
||||
errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this
|
||||
Licence.
|
||||
This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
|
||||
|
||||
8.Disclaimer of Liability
|
||||
Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be
|
||||
liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the
|
||||
Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss
|
||||
of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However,
|
||||
the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
|
||||
|
||||
9.Additional agreements
|
||||
While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services
|
||||
consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole
|
||||
responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by
|
||||
the fact You have accepted any warranty or additional liability.
|
||||
|
||||
10.Acceptance of the Licence
|
||||
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window
|
||||
displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of
|
||||
applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms
|
||||
and conditions.
|
||||
Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You
|
||||
by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution
|
||||
or Communication by You of the Work or copies thereof.
|
||||
|
||||
11.Information to the public
|
||||
In case of any Distribution or Communication of the Work by means of electronic communication by You (for example,
|
||||
by offering to download the Work from a remote location) the distribution channel or media (for example, a website)
|
||||
must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence
|
||||
and the way it may be accessible, concluded, stored and reproduced by the Licensee.
|
||||
|
||||
12.Termination of the Licence
|
||||
The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms
|
||||
of the Licence.
|
||||
Such a termination will not terminate the licences of any person who has received the Work from the Licensee under
|
||||
the Licence, provided such persons remain in full compliance with the Licence.
|
||||
|
||||
13.Miscellaneous
|
||||
Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the
|
||||
Work.
|
||||
If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or
|
||||
enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid
|
||||
and enforceable.
|
||||
The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of
|
||||
the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence.
|
||||
New versions of the Licence will be published with a unique version number.
|
||||
All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take
|
||||
advantage of the linguistic version of their choice.
|
||||
|
||||
14.Jurisdiction
|
||||
Without prejudice to specific agreement between parties,
|
||||
— any litigation resulting from the interpretation of this License, arising between the European Union institutions,
|
||||
bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice
|
||||
of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
|
||||
— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to
|
||||
the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
|
||||
|
||||
15.Applicable Law
|
||||
Without prejudice to specific agreement between parties,
|
||||
— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat,
|
||||
resides or has his registered office,
|
||||
— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside
|
||||
a European Union Member State.
|
||||
|
||||
|
||||
Appendix
|
||||
|
||||
‘Compatible Licences’ according to Article 5 EUPL are:
|
||||
— GNU General Public License (GPL) v. 2, v. 3
|
||||
— GNU Affero General Public License (AGPL) v. 3
|
||||
— Open Software License (OSL) v. 2.1, v. 3.0
|
||||
— Eclipse Public License (EPL) v. 1.0
|
||||
— CeCILL v. 2.0, v. 2.1
|
||||
— Mozilla Public Licence (MPL) v. 2
|
||||
— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
||||
— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
|
||||
— European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
||||
— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+).
|
||||
|
||||
The European Commission may update this Appendix to later versions of the above licences without producing
|
||||
a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the
|
||||
covered Source Code from exclusive appropriation.
|
||||
All other changes or additions to this Appendix require the production of a new EUPL version.
|
||||
@@ -1,10 +1,15 @@
|
||||
mortis.kamino Ansible Collection
|
||||
Copyright Defame1297 and contributors. Licensed GPL-3.0-or-later (see COPYING).
|
||||
The GPL-3.0-only file roles/ufw/templates/before.rules.j2 makes the Collection
|
||||
as a whole distributable under GPL-3.0 only.
|
||||
Files marked GPL-3.0-only (roles/pihole, roles/ufw/templates/before.rules.j2)
|
||||
make the Collection as a whole distributable under GPL-3.0 only.
|
||||
|
||||
This Collection contains third-party material. Each file carries an SPDX
|
||||
header naming its licence; licence texts are in LICENSES/.
|
||||
|
||||
- roles/pihole: derived from https://codeberg.org/ansible/pihole by Taha Ahmed
|
||||
(solarchemist), upstream commit 95a20d4 (GPL-3.0), modified by Defame1297.
|
||||
- roles/pihole/templates/pihole.toml.j2, roles/pihole/defaults/main.yml: comment
|
||||
text from Pi-hole FTL v6.2.2/v6.2.3, Copyright Pi-hole, LLC (EUPL-1.2); the
|
||||
combined work is distributed under GPL-3.0 per EUPL Art. 5.
|
||||
- roles/ufw/templates/before.rules.j2: derived from ufw conf/before.rules,
|
||||
Copyright 2008-2023 Canonical Ltd. (GPL-3.0-only).
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
|
||||
`cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`,
|
||||
`sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management`,
|
||||
plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap).
|
||||
`pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and
|
||||
`user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap).
|
||||
|
||||
Status: roles arrive in waves. Release 2.0.1 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call).
|
||||
Status: roles arrive in waves. Release 2.1.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `pihole`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call).
|
||||
|
||||
## Consuming
|
||||
|
||||
@@ -17,7 +17,7 @@ name (FQCN) only, `mortis.kamino.<role>`:
|
||||
collections:
|
||||
- name: https://git.rkdr.net/mortis/kamino.git
|
||||
type: git
|
||||
version: v2.0.1
|
||||
version: v2.1.0
|
||||
```
|
||||
|
||||
Its dependencies (`community.general`, `ansible.posix`) are declared in `galaxy.yml`, so
|
||||
@@ -39,7 +39,7 @@ when its own prerequisites (tests, a safe cutover wherever the role already runs
|
||||
|
||||
Still to come:
|
||||
|
||||
- Wave 2: `pve_vm`, `pve_lxc`, `tailscale`, `pihole`.
|
||||
- Wave 2: `pve_vm`, `tailscale`.
|
||||
- Wave 3: `rke2`, `proxmox_host`.
|
||||
- Later, wave not yet assigned: `opnsense`, `proxmox_firewall`.
|
||||
|
||||
@@ -49,9 +49,9 @@ Will not be extracted (they serve one lab or install that lab's own tool pins):
|
||||
|
||||
## Licence
|
||||
|
||||
Licensed GPL-3.0-or-later (see `COPYING`). The GPL-3.0-only file
|
||||
roles/ufw/templates/before.rules.j2 makes the Collection as a whole
|
||||
distributable under GPL-3.0 only. Third-party material
|
||||
Licensed GPL-3.0-or-later (see `COPYING`). Files marked GPL-3.0-only
|
||||
(roles/pihole, roles/ufw/templates/before.rules.j2) make the Collection as a
|
||||
whole distributable under GPL-3.0 only. Third-party material
|
||||
keeps its own licence, marked by an SPDX header, with texts in `LICENSES/` and
|
||||
attribution in `NOTICE`. The repository follows the REUSE specification
|
||||
(`reuse lint`).
|
||||
|
||||
+14
@@ -20,3 +20,17 @@ path = "roles/ufw/templates/before.rules.j2"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "2008-2023 Canonical Ltd."
|
||||
SPDX-License-Identifier = "GPL-3.0-only"
|
||||
|
||||
# Derived from https://codeberg.org/ansible/pihole by Taha Ahmed (solarchemist), commit 95a20d4.
|
||||
[[annotations]]
|
||||
path = "roles/pihole/**"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = ["Taha Ahmed (solarchemist)", "Defame1297 and contributors"]
|
||||
SPDX-License-Identifier = "GPL-3.0-only"
|
||||
|
||||
# The option comments came in via that upstream from Pi-hole FTL (https://github.com/pi-hole/FTL).
|
||||
[[annotations]]
|
||||
path = ["roles/pihole/templates/pihole.toml.j2", "roles/pihole/defaults/main.yml"]
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = ["Taha Ahmed (solarchemist)", "Pi-hole, LLC", "Defame1297 and contributors"]
|
||||
SPDX-License-Identifier = "GPL-3.0-only AND EUPL-1.2"
|
||||
@@ -31,6 +31,10 @@ objects:
|
||||
description: Manage /etc/network/interfaces
|
||||
name: network_interfaces
|
||||
version_added: null
|
||||
pihole:
|
||||
description: Install and configure Pi-hole from the upstream repository
|
||||
name: pihole
|
||||
version_added: null
|
||||
sshd:
|
||||
description: Write a hardened sshd drop-in
|
||||
name: sshd
|
||||
@@ -71,4 +75,4 @@ plugins:
|
||||
strategy: {}
|
||||
test: {}
|
||||
vars: {}
|
||||
version: 2.0.1
|
||||
version: 2.1.0
|
||||
@@ -376,3 +376,41 @@ releases:
|
||||
- docker-boot-shutdown-units.yml
|
||||
- role-readme-headings.yml
|
||||
release_date: '2026-11-25'
|
||||
2.1.0:
|
||||
changes:
|
||||
bugfixes:
|
||||
- system_baseline - the apt upgrade no longer loses its staged packages when
|
||||
it upgrades ``openssh-server`` on a host whose ``ssh.service`` has ``PrivateTmp=yes``.
|
||||
The restart of that unit deleted ``/tmp`` and ``/var/tmp`` in the middle of
|
||||
the upgrade, so dpkg failed with "cannot access archive" and left packages
|
||||
unpacked but not configured. The upgrade and the autoremove now run with ``TMPDIR``
|
||||
set to ``system_baseline_apt_tmpdir``, and the role opens a new connection
|
||||
afterwards.
|
||||
minor_changes:
|
||||
- docker - Add ``docker_daemon_options``, ``docker_live_restore``, ``docker_log_driver``,
|
||||
``docker_log_max_size``, ``docker_log_max_file`` and ``docker_daemon_restart``,
|
||||
which manage ``/etc/docker/daemon.json``. The file is written, before the
|
||||
packages are installed, only when at least one of the first five is set, so
|
||||
a host that sets none is unchanged; the role then owns the whole file. It
|
||||
restarts dockerd only when ``docker_daemon_restart`` is true (default ``false``),
|
||||
because a restart with ``live-restore`` off ends every container, and says
|
||||
that the file applies at the next restart otherwise. A key that ``docker_daemon_options``
|
||||
and a dedicated input both set, a bad ``docker_log_driver``, ``docker_log_max_size``
|
||||
or ``docker_log_max_file`` stops the run before any change.
|
||||
- pihole - New role. Installs Pi-hole v6 on Ubuntu noble by cloning the upstream
|
||||
repository and running its installer unattended, with ``pihole.toml`` rendered
|
||||
from ``pihole_default`` merged with ``pihole_overrides``. ``pihole_web_password``
|
||||
is a required secret input, and ``pihole_overrides`` must set ``config.dns.interface``.
|
||||
A change to ``pihole.toml`` runs the installer's reconfigure mode. Derived
|
||||
from codeberg.org/ansible/pihole (GPL-3.0-only), with Pi-hole FTL comment
|
||||
text (EUPL-1.2).
|
||||
- system_baseline - add ``system_baseline_apt_tmpdir`` (default ``/var/cache/system-baseline-apt-tmp``),
|
||||
the directory the apt upgrade and autoremove use as ``TMPDIR``. The role creates
|
||||
it (root, mode ``0700``) when it runs the ``update`` flow, including the ``update``
|
||||
entry point, and refuses a value under ``/tmp`` or ``/var/tmp``, a relative
|
||||
path or a ``..``.
|
||||
fragments:
|
||||
- docker-daemon-json.yml
|
||||
- pihole-role.yml
|
||||
- system-baseline-apt-tmpdir.yml
|
||||
release_date: '2026-11-25'
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
pve_lxc - New role. Creates, updates, grows the root disk of, starts, stops and (with ``pve_lxc_allow_destroy``)
|
||||
deletes a Proxmox VE LXC container through the Proxmox API (``community.proxmox``), reconciles the raw ``lxc.*``
|
||||
lines of its config on the node and, opt-in, writes its guest firewall file. Declares Debian trixie, untested;
|
||||
the molecule scenario covers the node-side files and the input validation, not the API lifecycle.
|
||||
@@ -12,7 +12,9 @@ It is the release the hosts are moving to; the roles are tested on it next to 24
|
||||
`ca-certificates`.
|
||||
- Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`.
|
||||
- The packages the roles manage, preinstalled so a converge makes no network calls:
|
||||
`iptables`, `ufw`, `fail2ban`, `openssh-server` (the `ssh` unit is enabled).
|
||||
`iptables`, `ufw`, `fail2ban`, `openssh-server` (the `ssh` unit is enabled), and `gnupg`
|
||||
(the docker scenario signs its stand-in APT repository with it).
|
||||
- root's `sudo` skips the PAM account check (`pam_rootok`), so `become` works in the container.
|
||||
- Throwaway SSH host keys and a machine-id generated at build time. They are not secrets and the
|
||||
image is a test target that must never be exposed to a network.
|
||||
|
||||
|
||||
@@ -57,3 +57,14 @@
|
||||
- name: NET_ADMIN is granted, so the firewall tools can work
|
||||
ansible.builtin.command: iptables -S
|
||||
changed_when: false
|
||||
|
||||
- name: Run a task with become, as the role scenarios do
|
||||
ansible.builtin.command: id -u
|
||||
become: true
|
||||
changed_when: false
|
||||
register: kamino_smoke_become
|
||||
|
||||
- name: Become reaches root
|
||||
ansible.builtin.assert:
|
||||
that: kamino_smoke_become.stdout == '0'
|
||||
quiet: true
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
---
|
||||
namespace: mortis
|
||||
name: kamino
|
||||
version: 2.0.1
|
||||
version: 2.1.0
|
||||
readme: README.md
|
||||
authors:
|
||||
- Defame1297
|
||||
description: >-
|
||||
Reusable, hardened Ansible roles for a self-hosted home lab (cloudflared, docker, fail2ban,
|
||||
gitea, gitea_runner, network_interfaces, sshd, system_baseline, systemd_hardening, traefik,
|
||||
ufw, user_management; _binary_update is internal).
|
||||
gitea, gitea_runner, network_interfaces, pihole, pve_lxc, sshd, system_baseline,
|
||||
systemd_hardening, traefik, ufw, user_management; _binary_update is internal).
|
||||
license:
|
||||
- GPL-3.0-or-later
|
||||
tags:
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# One RUN layer: about 30 MB compressed on top of the 29.8 MB base (estimated from
|
||||
# the real .debs, with the .pyc files the postinst scripts compile), far below
|
||||
# Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as
|
||||
# one request). apt packages are not version-pinned, as in the original image; the
|
||||
# one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the
|
||||
# base image is pinned by digest and a rebuild is a reviewed digest bump downstream.
|
||||
#
|
||||
# The image carries SSH host keys and a machine-id generated at build time (the
|
||||
@@ -36,7 +36,7 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2604" \
|
||||
org.opencontainers.image.authors="Defame1297 and contributors" \
|
||||
org.opencontainers.image.base.name="ubuntu:26.04" \
|
||||
net.rkdr.mortis.purpose="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection." \
|
||||
net.rkdr.mortis.contents="Ubuntu 26.04, systemd, systemd-sysv, dbus, sudo, iproute2, ca-certificates, python3, python3-apt, python3-systemd, iptables, ufw, fail2ban, openssh-server (ssh enabled)" \
|
||||
net.rkdr.mortis.contents="Ubuntu 26.04, systemd, systemd-sysv, dbus, sudo, iproute2, ca-certificates, python3, python3-apt, python3-systemd, iptables, ufw, fail2ban, openssh-server (ssh enabled), gnupg" \
|
||||
net.rkdr.mortis.usage="Molecule docker-driver platform with pre_build_image true, command /sbin/init, cgroupns_mode host, /sys/fs/cgroup mounted rw, tmpfs on /run and /run/lock, capability NET_ADMIN, security_opts apparmor=unconfined (not privileged). Pin git.rkdr.net/mortis/name:version@sha256:digest. See the documentation label."
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
@@ -44,15 +44,22 @@ ENV DEBIAN_FRONTEND=noninteractive
|
||||
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
|
||||
# the target (python3-apt for the apt module); the firewall and intrusion-prevention
|
||||
# packages the roles manage (python3-systemd is a dependency of fail2ban's systemd
|
||||
# backend); sshd, enabled so a converge can test it under systemd.
|
||||
# backend); sshd, enabled so a converge can test it under systemd; gnupg, which the docker
|
||||
# scenario signs its stand-in APT repository with and which would otherwise cost it an
|
||||
# apt update and install in every run.
|
||||
# root's sudo (Ansible's become here) skips pam_unix's account check, whose unix_chkpwd
|
||||
# helper fails inside the container; non-root callers still go through pam_unix.
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
systemd systemd-sysv dbus sudo iproute2 ca-certificates \
|
||||
python3 python3-apt python3-systemd \
|
||||
iptables ufw fail2ban \
|
||||
openssh-server \
|
||||
gnupg \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& systemctl enable ssh
|
||||
&& systemctl enable ssh \
|
||||
&& sed -i '0,/^@include common-account/s//account sufficient pam_rootok.so\n@include common-account/' /etc/pam.d/sudo \
|
||||
&& grep -qx 'account sufficient pam_rootok.so' /etc/pam.d/sudo
|
||||
|
||||
STOPSIGNAL SIGRTMIN+3
|
||||
CMD ["/sbin/init"]
|
||||
@@ -214,10 +214,14 @@ ansible-lint==26.10.1 \
|
||||
# via
|
||||
# -r requirements-dev.txt
|
||||
# galaxy-importer
|
||||
antsibull-changelog==0.37.0 \
|
||||
--hash=sha256:649105fe6ccd4f035688c4e2e580573660712af1e46f8c0d3d8891352ffc7e2e \
|
||||
--hash=sha256:c9fb0e7625b208ae4ea6fe3633bc0dbeb029bcd2a79da36a8ef7f5a256beadc4
|
||||
antsibull-changelog==0.38.0 \
|
||||
--hash=sha256:674989862b8518ad14bb3ba2b149dc4d70f180666102e0f104864efa6f62ae21 \
|
||||
--hash=sha256:a37d7cd00943e97ed076eb9426a7cd5cd675b247209300ea719948ceaddc9d63
|
||||
# via -r requirements-dev.txt
|
||||
antsibull-docs-loader==1.0.0 \
|
||||
--hash=sha256:92ec1647c24e9006efe7bb7525f3087b9ac70c878da2f2a1b105e7485fd7b240 \
|
||||
--hash=sha256:c1c08623c14d3fc02add4b927678690174f8a082543ea0a48fd61e3647dcd053
|
||||
# via antsibull-changelog
|
||||
antsibull-docs-parser==1.2.3 \
|
||||
--hash=sha256:0d4835c615b6ae1b64d219d42260c2e1b58b6312809599e8e1a63adf7797e968 \
|
||||
--hash=sha256:66d593ad90d5499112cc3167fb178bfa787b496eb883102dfe12a4a4047406ba
|
||||
@@ -1939,6 +1943,7 @@ pyyaml==6.0.4 \
|
||||
# ansible-compat
|
||||
# ansible-core
|
||||
# ansible-lint
|
||||
# antsibull-docs-loader
|
||||
# antsibull-fileutils
|
||||
# apm-cli
|
||||
# galaxy-importer
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
ansible-core==2.22.0
|
||||
ansible-lint==26.10.1
|
||||
pre-commit==4.7.0
|
||||
antsibull-changelog==0.37.0
|
||||
antsibull-changelog==0.38.0
|
||||
galaxy-importer==0.4.44
|
||||
reuse==6.3.0
|
||||
molecule==26.11.0
|
||||
|
||||
+18
-1
@@ -35,13 +35,19 @@ The role targets Ubuntu hosts only: it installs from Docker's Ubuntu repository,
|
||||
| `docker_start_missed_settle_seconds` | `30` | no | Seconds the boot unit waits after Docker answers, so dockerd's own restarts finish first. |
|
||||
| `docker_stop_at_shutdown` | `false` | no | Install a unit that ends container processes at shutdown while the network and NFS are still up. |
|
||||
| `docker_stop_at_shutdown_timeout` | `30` | no | Seconds the shutdown unit waits after SIGTERM before it sends SIGKILL (at least 1). |
|
||||
| `docker_daemon_options` | `{}` | no | Extra keys merged into `/etc/docker/daemon.json` (see [Daemon settings](#daemon-settings)). |
|
||||
| `docker_live_restore` | `false` | no | Write `"live-restore": true`. |
|
||||
| `docker_log_driver` | empty | no | Written as `log-driver`, for example `local`. |
|
||||
| `docker_log_max_size` | empty | no | Written as the `max-size` log option, for example `10m`. |
|
||||
| `docker_log_max_file` | empty | no | Written as the `max-file` log option, a string, for example `"3"`. |
|
||||
| `docker_daemon_restart` | `false` | no | Restart dockerd when `daemon.json` changed. |
|
||||
| `docker_service` | `docker` | no | systemd unit name. |
|
||||
| `docker_group` | `docker` | no | Group for `docker_users`. |
|
||||
| `docker_users` | `[]` | no | Users added to the group. |
|
||||
|
||||
## Tags
|
||||
|
||||
`docker` (everything), `install`, `update`, `remove`, `configure` (group membership and the two units). The tasks in `remove.yml` carry `docker` and `remove`.
|
||||
`docker` (everything), `install`, `update`, `remove`, `configure` (group membership, the daemon settings and the two units). The tasks in `remove.yml` carry `docker` and `remove`.
|
||||
|
||||
Update (`docker_update: true`) and removal (`docker_remove: true`) are opt-in: run them on a host that is safe to change.
|
||||
|
||||
@@ -60,6 +66,16 @@ Things to know before you switch `docker_stop_at_shutdown` on:
|
||||
- The script reads the layout of the systemd cgroup driver on cgroup v2 (`/sys/fs/cgroup/system.slice/docker-<id>.scope`, and the cgroups below it). On a host that lays containers out differently it finds nothing, logs "no container scopes" and changes nothing, so check the journal (`journalctl -t docker-stop-at-shutdown -b -1`) after the first reboot.
|
||||
- `docker-start-missed --dry-run` lists what the boot unit would start; add `--settle 0` to skip the wait.
|
||||
|
||||
## Daemon settings
|
||||
|
||||
With any of `docker_daemon_options`, `docker_live_restore`, `docker_log_driver`, `docker_log_max_size` or `docker_log_max_file` set, the role writes `/etc/docker/daemon.json` (root, mode `0644`, valid JSON) before it installs the packages, so a first start of dockerd already reads it. With none set, it writes nothing and leaves an existing file alone.
|
||||
|
||||
- **The role owns the whole file.** A key that is not in the inputs is removed, including one a person added by hand. Put every key you need in `docker_daemon_options`.
|
||||
- **A key set twice is refused.** `live-restore`, `log-driver` and `log-opts` in `docker_daemon_options` stop the run when the dedicated input also sets them.
|
||||
- **No restart by default.** A change applies at the next dockerd restart, and the role says so. A restart with `live-restore` off ends every container, so `docker_daemon_restart: true` is for a host where that is acceptable, or one that already runs with `live-restore` and whose change needs no more than a restart. Not every key can be applied by a reload; see the Docker documentation for the ones that can.
|
||||
- **A bad value stops dockerd, not the role.** The role checks the shape of the log inputs, not whether the driver accepts the options: dockerd refuses to start with a rejected one (the `local` driver, for example, refuses some `max-file` and `compress` combinations). Try a new value on a host that can be down before it reaches the others.
|
||||
- Setting an input back to its default does not remove a key from a file already written; `docker_remove` leaves the file in place.
|
||||
|
||||
## Example play
|
||||
|
||||
```yaml
|
||||
@@ -81,6 +97,7 @@ What it shows, with the role's tasks running unchanged:
|
||||
- The packages are installed from that repository, the unit is enabled and active, and `docker_users` join `docker_group`.
|
||||
- `docker_remove` with `docker_remove_data` removes the source line, the keyring, the packages, the unit and `/var/lib/docker`.
|
||||
- Both units are installed, enabled, ordered against `docker.service` as stated, the shutdown unit is active, a unit is removed when its input is `false`, and `docker_remove` removes both.
|
||||
- With the daemon inputs set, `/etc/docker/daemon.json` is valid JSON with exactly the expected keys, mode `0644` and root-owned. A change with `docker_daemon_restart: false` leaves dockerd running (its start time is unchanged); with `true` it restarts it. A key set both in `docker_daemon_options` and by a dedicated input, and a bad log size, driver or file count, are refused before any change.
|
||||
- The argument check refuses a mapping for `docker_users`, a non-boolean `docker_remove` and a `docker_stop_at_shutdown_timeout` of 0.
|
||||
- A second run changes nothing (molecule's idempotence check).
|
||||
|
||||
|
||||
@@ -46,3 +46,17 @@ docker_start_missed_settle_seconds: 30
|
||||
# Off by default; set it on a host whose containers mount NFS shares.
|
||||
docker_stop_at_shutdown: false
|
||||
docker_stop_at_shutdown_timeout: 30
|
||||
|
||||
# /etc/docker/daemon.json. The role writes the file only when at least one of these is set, and then owns it whole: a key it does not
|
||||
# know is removed. Nothing is written by default, so a host that sets none of them keeps its file. The role restarts dockerd only when
|
||||
# docker_daemon_restart is true (a restart with live-restore off ends every container); otherwise the file applies at the next restart.
|
||||
# Extra daemon.json keys, merged as they are; a key that a dedicated input below also sets is refused.
|
||||
docker_daemon_options: {}
|
||||
# true writes "live-restore": true, so a docker.service restart leaves running containers alone.
|
||||
docker_live_restore: false
|
||||
# "log-driver" (for example local) and the "max-size" and "max-file" log options (for example 10m and "3", quoted). Empty writes nothing.
|
||||
docker_log_driver: ""
|
||||
docker_log_max_size: ""
|
||||
docker_log_max_file: ""
|
||||
# true restarts dockerd when the file changed.
|
||||
docker_daemon_restart: false
|
||||
@@ -102,6 +102,50 @@ argument_specs:
|
||||
default: 30
|
||||
description:
|
||||
- Seconds the unit waits for container processes to end after SIGTERM before it sends SIGKILL. At least 1.
|
||||
docker_daemon_options:
|
||||
type: dict
|
||||
default: {}
|
||||
description:
|
||||
- >-
|
||||
Keys merged as they are into C(/etc/docker/daemon.json), for any setting the dedicated inputs below do not cover. A key that a
|
||||
dedicated input also sets (C(live-restore), C(log-driver) or C(log-opts)) stops the run. When this or any other daemon input is
|
||||
set the role owns the whole file: a key it does not know is removed. Nothing is written when every daemon input is at its default.
|
||||
docker_live_restore:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- >-
|
||||
true writes C(live-restore) true to C(/etc/docker/daemon.json), so a C(docker.service) restart leaves running containers alone.
|
||||
It takes effect at the next dockerd restart. Setting it back to false does not remove the key from a file already written.
|
||||
docker_log_driver:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Default logging driver written as C(log-driver) (for example C(local) or C(json-file)); lowercase letters, digits and C(-).
|
||||
Empty writes nothing. The role does not check that the driver accepts the log options below: dockerd refuses to start with one
|
||||
it rejects.
|
||||
docker_log_max_size:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Written as the C(max-size) log option, a whole number with an optional C(k), C(m) or C(g) (for example C(10m)), or C(-1).
|
||||
Empty writes nothing.
|
||||
docker_log_max_file:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Written as the C(max-file) log option, a whole number of at least 1. Quote it, because the input is a string. Empty writes
|
||||
nothing.
|
||||
docker_daemon_restart:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- >-
|
||||
true restarts dockerd when C(/etc/docker/daemon.json) changed. false (the default) leaves the running daemon alone, because a
|
||||
restart with C(live-restore) off ends every container; the file then applies at the next restart and the role says so.
|
||||
docker_service:
|
||||
type: str
|
||||
default: docker
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
docker_start_missed: true
|
||||
docker_stop_at_shutdown: true
|
||||
docker_stop_at_shutdown_timeout: 20
|
||||
docker_live_restore: true
|
||||
docker_log_driver: local
|
||||
docker_log_max_size: 10m
|
||||
docker_log_max_file: "3"
|
||||
docker_daemon_options:
|
||||
max-concurrent-downloads: 3
|
||||
roles:
|
||||
- role: mortis.kamino.docker
|
||||
|
||||
@@ -109,3 +115,21 @@
|
||||
- "'MOLECULE-ACCEPTED' not in ansible_failed_result.msg | default('')"
|
||||
- "'docker_stop_at_shutdown_timeout' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
# A key that docker_daemon_options and a dedicated input both set, and a log value dockerd would reject, stop the run before any change.
|
||||
- name: A bad daemon setting is refused
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Apply the role with each bad setting
|
||||
ansible.builtin.include_tasks: tasks/refuse_daemon.yml
|
||||
vars:
|
||||
docker_refused: "{{ item }}"
|
||||
loop:
|
||||
- {docker_live_restore: true, docker_daemon_options: {live-restore: false}}
|
||||
- {docker_log_driver: local, docker_daemon_options: {log-driver: json-file}}
|
||||
- {docker_log_max_size: 10m, docker_daemon_options: {log-opts: {max-size: 1m}}}
|
||||
- {docker_log_driver: Local}
|
||||
- {docker_log_max_size: ten}
|
||||
- {docker_log_max_file: "0"}
|
||||
- {docker_log_max_file: "-1"}
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
# The stand-in repository is not needed: validation stops the role before the first change.
|
||||
- name: Run the role with a bad daemon setting
|
||||
block:
|
||||
- name: Include the role
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_live_restore: "{{ docker_refused.docker_live_restore | default(false) }}"
|
||||
docker_log_driver: "{{ docker_refused.docker_log_driver | default('') }}"
|
||||
docker_log_max_size: "{{ docker_refused.docker_log_max_size | default('') }}"
|
||||
docker_log_max_file: "{{ docker_refused.docker_log_max_file | default('') }}"
|
||||
docker_daemon_options: "{{ docker_refused.docker_daemon_options | default({}) }}"
|
||||
- name: Fail when the bad setting was accepted
|
||||
ansible.builtin.fail:
|
||||
msg: MOLECULE-ACCEPTED
|
||||
rescue:
|
||||
- name: The validation stopped the play
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'MOLECULE-ACCEPTED' not in ansible_failed_result.msg | default('')"
|
||||
- "'docker_' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -203,6 +203,94 @@
|
||||
vars:
|
||||
docker_start_missed: true
|
||||
|
||||
- name: Verify the daemon settings
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
docker_verify_expected:
|
||||
live-restore: true
|
||||
log-driver: local
|
||||
log-opts:
|
||||
max-file: "3"
|
||||
max-size: 10m
|
||||
max-concurrent-downloads: 3
|
||||
tasks:
|
||||
- name: Read and stat daemon.json
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/docker/daemon.json
|
||||
register: docker_verify_daemon
|
||||
|
||||
- name: Stat daemon.json
|
||||
ansible.builtin.stat:
|
||||
path: /etc/docker/daemon.json
|
||||
register: docker_verify_daemon_stat
|
||||
|
||||
- name: The file holds exactly the keys the converge set, root-owned with mode 0644
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- docker_verify_daemon.content | b64decode | from_json == docker_verify_expected
|
||||
- docker_verify_daemon_stat.stat.mode == '0644'
|
||||
- docker_verify_daemon_stat.stat.pw_name == 'root'
|
||||
quiet: true
|
||||
|
||||
# The stand-in docker.service runs for real, so a restart shows in its start time: a changed file with docker_daemon_restart false leaves
|
||||
# it alone, and with true restarts it.
|
||||
- name: Verify that dockerd restarts only when asked
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: true
|
||||
docker_stop_at_shutdown: true
|
||||
docker_stop_at_shutdown_timeout: 20
|
||||
docker_log_driver: local
|
||||
docker_log_max_size: 10m
|
||||
docker_log_max_file: "3"
|
||||
docker_live_restore: true
|
||||
tasks:
|
||||
- name: Read the start time of the service
|
||||
ansible.builtin.command: systemctl show -p ActiveEnterTimestampMonotonic docker.service # noqa: command-instead-of-module
|
||||
register: docker_verify_before
|
||||
changed_when: false
|
||||
|
||||
- name: Apply a changed setting with docker_daemon_restart false
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_daemon_options: {max-concurrent-downloads: 5}
|
||||
docker_daemon_restart: false
|
||||
|
||||
- name: Read the start time again
|
||||
ansible.builtin.command: systemctl show -p ActiveEnterTimestampMonotonic docker.service # noqa: command-instead-of-module
|
||||
register: docker_verify_kept
|
||||
changed_when: false
|
||||
|
||||
- name: Apply another change with docker_daemon_restart true
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_daemon_options: {max-concurrent-downloads: 6}
|
||||
docker_daemon_restart: true
|
||||
|
||||
- name: Read the start time a third time
|
||||
ansible.builtin.command: systemctl show -p ActiveEnterTimestampMonotonic docker.service # noqa: command-instead-of-module
|
||||
register: docker_verify_restarted
|
||||
changed_when: false
|
||||
|
||||
- name: Read daemon.json
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/docker/daemon.json
|
||||
register: docker_verify_daemon_after
|
||||
|
||||
- name: The first change left dockerd alone and the second restarted it
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- docker_verify_kept.stdout == docker_verify_before.stdout
|
||||
- docker_verify_restarted.stdout != docker_verify_kept.stdout
|
||||
- (docker_verify_daemon_after.content | b64decode | from_json)['max-concurrent-downloads'] == 6
|
||||
quiet: true
|
||||
|
||||
# docker_remove_data is set, so this also covers the destructive path: the packages are
|
||||
# purged and /var/lib/docker, seeded in prepare.yml, is deleted. The removal stops the unit
|
||||
# before the package takes it away, so it can only run once; a second run would fail on the
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
# Written before the packages are installed, so a first start of dockerd already reads it. On a host that runs Docker the file takes effect
|
||||
# at the next daemon restart: this role restarts dockerd only when docker_daemon_restart is true, because a restart with live-restore
|
||||
# off ends every container.
|
||||
- name: Collect the log options
|
||||
ansible.builtin.set_fact:
|
||||
__docker_log_opts: >-
|
||||
{{ ({'max-size': docker_log_max_size} if docker_log_max_size | length > 0 else {})
|
||||
| combine({'max-file': docker_log_max_file} if docker_log_max_file | length > 0 else {}) }}
|
||||
tags: [docker, configure]
|
||||
|
||||
- name: Work out the daemon settings
|
||||
ansible.builtin.set_fact:
|
||||
__docker_daemon_config: >-
|
||||
{{ docker_daemon_options
|
||||
| combine({'live-restore': true} if docker_live_restore | bool else {})
|
||||
| combine({'log-driver': docker_log_driver} if docker_log_driver | length > 0 else {})
|
||||
| combine({'log-opts': __docker_log_opts} if __docker_log_opts | length > 0 else {}) }}
|
||||
tags: [docker, configure]
|
||||
|
||||
- name: Create the Docker configuration directory
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: /etc/docker
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
when: __docker_daemon_config | length > 0
|
||||
tags: [docker, configure]
|
||||
|
||||
- name: Write the daemon settings
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/docker/daemon.json
|
||||
content: "{{ __docker_daemon_config | to_nice_json }}\n"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
register: __docker_daemon_file
|
||||
notify: "{{ ['Restart docker'] if docker_daemon_restart | bool else [] }}"
|
||||
when: __docker_daemon_config | length > 0
|
||||
tags: [docker, configure]
|
||||
|
||||
- name: Say when the daemon settings apply
|
||||
ansible.builtin.debug:
|
||||
msg: /etc/docker/daemon.json changed. dockerd reads it at its next restart; set docker_daemon_restart to restart it from this role.
|
||||
when:
|
||||
- __docker_daemon_file is changed
|
||||
- not (docker_daemon_restart | bool)
|
||||
tags: [docker, configure]
|
||||
@@ -9,6 +9,11 @@
|
||||
when: docker_remove | default(false) | bool
|
||||
tags: [docker, remove]
|
||||
|
||||
- name: Write the daemon settings
|
||||
ansible.builtin.include_tasks: daemon.yml
|
||||
when: not (docker_remove | default(false) | bool)
|
||||
tags: [docker, configure]
|
||||
|
||||
- name: Install Docker Engine
|
||||
ansible.builtin.include_tasks: install.yml
|
||||
when: not (docker_remove | default(false) | bool)
|
||||
|
||||
@@ -31,3 +31,29 @@
|
||||
docker_start_missed_settle_seconds must be a whole number of at least 0 and docker_stop_at_shutdown_timeout a whole number of at least 1.
|
||||
quiet: true
|
||||
tags: always
|
||||
|
||||
# The values go into daemon.json, which dockerd refuses to start with when it holds a bad one, so a shape check stops the run first.
|
||||
- name: Check the daemon log settings
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- docker_log_driver is match('^[a-z0-9-]*\Z')
|
||||
- docker_log_max_size is match('^(-1|[0-9]+[kKmMgG]?)?\Z')
|
||||
- docker_log_max_file is match('^[0-9]*\Z')
|
||||
- docker_log_max_file | length == 0 or docker_log_max_file | int >= 1
|
||||
fail_msg: >-
|
||||
docker_log_driver must be empty or lowercase letters, digits and -; docker_log_max_size empty, -1 or a whole number with an optional
|
||||
k, m or g (for example 10m); docker_log_max_file empty or a whole number of at least 1 (quote it).
|
||||
quiet: true
|
||||
tags: always
|
||||
|
||||
- name: Refuse a daemon option that a dedicated input also sets
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- not (docker_live_restore | bool and 'live-restore' in docker_daemon_options)
|
||||
- not (docker_log_driver | length > 0 and 'log-driver' in docker_daemon_options)
|
||||
- not ((docker_log_max_size | length > 0 or docker_log_max_file | length > 0) and 'log-opts' in docker_daemon_options)
|
||||
fail_msg: >-
|
||||
docker_daemon_options sets a key that a dedicated input also sets: live-restore (docker_live_restore), log-driver (docker_log_driver)
|
||||
or log-opts (docker_log_max_size and docker_log_max_file). Set it in one place.
|
||||
quiet: true
|
||||
tags: always
|
||||
@@ -0,0 +1,83 @@
|
||||
# pihole
|
||||
|
||||
Installs [Pi-hole](https://pi-hole.net) v6 by cloning the upstream repository and running its installer unattended, with `pihole.toml` rendered by the role from a merged settings dictionary. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
|
||||
|
||||
## Supported platforms
|
||||
|
||||
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The role asserts that the host is Ubuntu before any change. The package dependencies come from `ansible.builtin.apt`. The host needs outbound access to the upstream Pi-hole repository (`repo.remote` in the merged settings) and to the apt mirrors.
|
||||
|
||||
Untested platforms: Ubuntu 26.04 (resolute). The apt dependencies exist there, but the scenario does not run on it yet.
|
||||
|
||||
The role targets Ubuntu hosts that serve DNS, not Proxmox nodes, so it does not cover Debian trixie: the upstream installer is run on the Ubuntu hosts it is tested on.
|
||||
|
||||
## Requirements and run order
|
||||
|
||||
- Use it by its fully qualified name, `mortis.kamino.pihole`, in a play that gathers facts: the role reads the `env` and `user_id` facts, and fails at the Ubuntu assert without facts.
|
||||
- Role dependencies: none.
|
||||
- `pihole_web_password` is required (argument spec): a secret of its own, sourced from a vaulted variable. It is needed even when `pihole_overrides` sets the password, because the merge templates all of `pihole_default`, which references it.
|
||||
- `pihole_overrides` must set `config.dns.interface`, which has no usable default.
|
||||
- `become` is used for the package, user, file, template and installer tasks. The repository is cloned as the connecting user (the `user_id` fact).
|
||||
|
||||
## Role variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `pihole_web_password` | none (required) | The web/API password, the default of the merged `config.webserver.api.password`. `no_log`. |
|
||||
| `pihole_overrides` | `{}` | Overrides merged recursively over `pihole_default`. Must set `config.dns.interface`. |
|
||||
| `pihole_default` | all Pi-hole settings, see `defaults/main.yml` | Every setting rendered into `pihole.toml`. Override keys through `pihole_overrides`, not by redefining it. |
|
||||
| `pihole_testing` | `false` | Print the merged settings (secrets masked), pause, and on a first install print the installer log. |
|
||||
| `pihole_testing_timeout` | `5` | Seconds to pause when testing. |
|
||||
| `pihole_install_script` | the quoted `<repo.path>/automated install/basic-install.sh` | Installer command. |
|
||||
| `pihole_apt_dependencies` | curl, git, procps, lighttpd-mod-deflate, apt-utils, whiptail, dnsutils, bc, unzip, wget, sudo, netcat-openbsd, cron, iproute2 | apt packages installed first. Overriding replaces the list. |
|
||||
|
||||
`pihole_default` and `pihole_install_script` are not in the argument spec, because argument validation templates every listed variable: `pihole_install_script` reads the merged settings, which the role sets only after validation, and templating `pihole_default` would turn a missing `pihole_web_password` into an undefined-variable error before the clean "missing required arguments" message.
|
||||
|
||||
Keys of `pihole_overrides` that the role itself reads: `repo.remote`, `repo.version` (default `v6.4`), `repo.path` (default `~/.cache/pi-hole`), `user` and `group` (default `pihole`), `config.files.database` (its directory receives `pihole.toml`), `config.dns.upstreams` (must stay a non-empty list), `config.dns.interface` (must be a non-empty string) and `config.webserver.api.password` (must stay a string other than `changetoyourownpassword`). Every other key is rendered into `pihole.toml` by the template.
|
||||
|
||||
The upstreams default to `1.1.1.1` and `8.8.8.8`, `config.dns.domain` to `lan` and the password to `pihole_web_password`. Source an overridden password from a vaulted variable.
|
||||
|
||||
## Tags
|
||||
|
||||
The input asserts carry `always` (and `assert`), so they run whatever tags are selected. The merge, the installed check and the configuration-directory check, which only compute facts, carry `always` too, so skipping a tag never skips a fact a later task reads. The reconfigure import carries `config-only`. The version fact, configuration and installation tasks carry no tag of their own, so they run only when no tags are selected.
|
||||
|
||||
## Example play
|
||||
|
||||
```yaml
|
||||
- name: Run Pi-hole
|
||||
hosts: dns_servers
|
||||
roles:
|
||||
- role: mortis.kamino.pihole
|
||||
vars:
|
||||
pihole_web_password: "{{ vault_pihole_web_password }}"
|
||||
pihole_overrides:
|
||||
config:
|
||||
dns:
|
||||
interface: eth0
|
||||
upstreams:
|
||||
- 9.9.9.9
|
||||
- 149.112.112.112
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
The `default` molecule scenario runs on noble. It replaces the upstream repository with a local stub whose installer only logs its arguments and creates the database file, so it tests the merge, the asserts, the user, the configuration directory and the rendered `pihole.toml` (owner, group and mode), the clone's checked-out version, the installer sequence (install once, then reconfigure from the handler) and idempotence, not Pi-hole itself: no pihole-FTL service runs, so that the service loaded the configuration is not verified. It runs `check` before the converge (a first-run preview) and after the idempotence run. Negative tests in `verify.yml` cover a host without Ubuntu facts, a missing `pihole_web_password`, an unset interface, empty upstreams, a non-string password and the placeholder password.
|
||||
|
||||
## Notes
|
||||
|
||||
- Idempotent: yes.
|
||||
- Merge model: the role sets an internal fact to `pihole_default | combine(pihole_overrides | default({}), recursive=True)`. The input is only read, never overwritten, so each run recomputes the merge. Dictionaries are not merged across variable sources, so define `pihole_overrides` in one place only.
|
||||
- Secrets: the password is hashed twice with SHA-256 in the template (`pwhash`). The merge and both template tasks use `no_log`, and the templates `diff: false`, so a `pihole.toml` change shows no diff. `pihole_testing` masks the web password, app password and TOTP secret in its output. `totp_secret` and `app_password` default to empty strings.
|
||||
- Install flow: the role creates the `pihole` system user (nologin), the configuration directory and, on first install, `pihole.toml`, because the unattended installer needs it first. It clones `repo.version` and runs the installer with `--unattended` only when `config.files.database` does not exist yet. A change to `pihole.toml` notifies the `reconfigure pihole` handler, which runs the installer with `--reconfigure --unattended`.
|
||||
- Updates: the role does not upgrade an installed Pi-hole; changing `repo.version` only moves the clone.
|
||||
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host where the configuration directory does not exist yet, the `pihole.toml` template tasks are skipped under `--check`, because the directory they write into is not created.
|
||||
- `misc.readOnly` defaults to `true`, so Pi-hole does not change `pihole.toml` through its API or CLI and the role's rendering stays authoritative.
|
||||
- The web interface listens on ports 8080 and 8443 by default (`config.webserver.port`), not 80. The role defines no firewall rules.
|
||||
- The FTL database keeps queries for `config.database.maxDBdays` days (default 91) and can grow large; lower that key to limit it.
|
||||
- Double-hash a password by hand from stdin, for comparison with `pwhash`:
|
||||
|
||||
```
|
||||
echo -n somelongandsecretstringofyourown | sha256sum | awk '{printf "%s",$1 }' | sha256sum
|
||||
```
|
||||
|
||||
- Upstream references, not verified by this repository: https://github.com/pi-hole/pi-hole, https://docs.pi-hole.net/ftldns/configfile, https://github.com/pi-hole/pi-hole/issues/5283, https://discourse.pi-hole.net/t/support-writing-to-pihole-toml-directly/70522.
|
||||
- `no_log` is used on every task that carries the password; see Secrets above.
|
||||
@@ -0,0 +1,514 @@
|
||||
---
|
||||
# SPDX-License-Identifier: GPL-3.0-only AND EUPL-1.2
|
||||
# Derived from https://codeberg.org/ansible/pihole by Taha Ahmed (solarchemist),
|
||||
# modified by Defame1297. The option comments came in via that upstream from
|
||||
# Pi-hole FTL v6.2.2/v6.2.3 (Copyright Pi-hole, LLC, EUPL-1.2); see NOTICE.
|
||||
|
||||
pihole_default:
|
||||
repo:
|
||||
remote: "https://github.com/pi-hole/pi-hole.git"
|
||||
# use "version: latest" to get the latest *release*, or specify a version
|
||||
# to install, e.g., "version: 'v6.1.4'"
|
||||
version: "v6.4"
|
||||
# I don't like using /tmp because it requires running git as root
|
||||
# most suitable "tmp"-like path under user's HOME is ~/.cache/ I guess
|
||||
path: "{{ ansible_facts['env']['HOME'] }}/.cache/pi-hole"
|
||||
gh_slug: "pi-hole/pi-hole"
|
||||
user: pihole
|
||||
group: pihole
|
||||
# configure /etc/pihole/pihole.toml
|
||||
# I chose to configure it this way because neither lineinfile nor blockinfile modules
|
||||
# are suitable for handling TOML files
|
||||
# https://stackoverflow.com/questions/79673679/ansible-lineinfile-and-replace-modules-attempting-to-configure-toml-txt-file
|
||||
config:
|
||||
dns:
|
||||
# array of IP addresses and/or hostnames, optionally with a port (#...)
|
||||
# dns_servers:
|
||||
upstreams:
|
||||
- "1.1.1.1"
|
||||
- "8.8.8.8"
|
||||
# Use this option to control deep CNAME inspection. Disabling it might be beneficial
|
||||
# for very low-end devices
|
||||
CNAMEdeepInspect: true
|
||||
blockESNI: true
|
||||
EDNS0ECS: true
|
||||
# Should FTL hide queries made by localhost?
|
||||
ignoreLocalhost: false
|
||||
# Should FTL analyze and show internally generated DNSSEC queries?
|
||||
showDNSSEC: true
|
||||
# Should FTL analyze *only* A and AAAA queries?
|
||||
analyzeOnlyAandAAAA: false
|
||||
# Changing this setting causes FTL to restart.
|
||||
# Possible values are "NONE", "HOSTNAME", "HOSTNAMEFQDN", or "PI.HOLE"
|
||||
piholePTR: "PI.HOLE"
|
||||
# How should FTL handle queries when the gravity database is not available?
|
||||
# Possible values are: "BLOCK", "ALLOW", "REFUSE", "DROP"
|
||||
replyWhenBusy: "DROP"
|
||||
blockTTL: 2
|
||||
# List of custom DNS records
|
||||
hosts: []
|
||||
# If set, A and AAAA queries for plain names, without dots or domain parts, are never
|
||||
# forwarded to upstream nameservers
|
||||
# Is true a better default (for Unbound)? # https://github.com/community-scripts/ProxmoxVE/discussions/2508
|
||||
domainNeeded: false
|
||||
# If set, the domain is added to simple names (without a period) in /etc/hosts in the
|
||||
# same way as for DHCP-derived names
|
||||
# Is true a better default (for Unbound)? # https://github.com/community-scripts/ProxmoxVE/discussions/2508
|
||||
expandHosts: false
|
||||
# The DNS domain used by your Pi-hole.
|
||||
# You can disable setting a domain by setting this option to an empty string.
|
||||
domain: "lan"
|
||||
# Should all reverse lookups for private IP ranges (i.e., 192.168.x.y, etc) which are
|
||||
# not found in /etc/hosts or the DHCP leases file be answered with "no such domain"
|
||||
# rather than being forwarded upstream?
|
||||
bogusPriv: true
|
||||
# Validate DNS replies using DNSSEC?
|
||||
dnssec: false
|
||||
# Interface to use for DNS (see also dnsmasq.listening.mode) and DHCP (if enabled)
|
||||
# Host-specific: empty placeholder, the role fails until it is set through
|
||||
# pihole_overrides (see tasks/validate.yml).
|
||||
interface: ""
|
||||
# Add A, AAAA and PTR records to the DNS.
|
||||
hostRecord: ""
|
||||
# Pi-hole interface listening modes
|
||||
# Possible values are: LOCAL, SINGLE, BIND, ALL, NONE
|
||||
listeningMode: "LOCAL"
|
||||
# Log DNS queries and replies to pihole.log
|
||||
queryLogging: true
|
||||
cnameRecords: []
|
||||
# Port used by the DNS server
|
||||
port: 53
|
||||
# Reverse server (former also called "conditional forwarding") feature
|
||||
# Array of reverse servers each one in one of the following forms:
|
||||
# "<enabled>,<ip-address>[/<prefix-len>],<server>[#<port>][,<domain>]"
|
||||
revServers: []
|
||||
# [dns.cache]
|
||||
cache:
|
||||
# Cache size of the DNS server. Note that expiring cache entries naturally make room
|
||||
# for new insertions over time. Setting this number too high will have an adverse
|
||||
# effect as not only more space is needed, but also lookup speed gets degraded in the
|
||||
# 10,000+ range. dnsmasq may issue a warning when you go beyond 10,000+ cache entries.
|
||||
size: 10000
|
||||
# Query cache optimizer: If a DNS name exists in the cache, but its time-to-live has
|
||||
# expired only recently, the data will be used anyway (a refreshing from upstream is
|
||||
# triggered). This can improve DNS query delays especially over unreliable Internet
|
||||
# connections.
|
||||
optimizer: 3600
|
||||
# This setting allows you to specify the TTL used for queries blocked upstream. Once
|
||||
# the TTL expires, the query will be forwarded to the upstream server again to check
|
||||
# if the block is still valid. Defaults to caching for one day (86400 seconds).
|
||||
upstreamBlockedTTL: 86400
|
||||
# [dns.blocking]
|
||||
blocking:
|
||||
# Should FTL block queries?
|
||||
active: true
|
||||
# How should FTL reply to blocked queries?
|
||||
# Possible values are: NULL, IP_NODATA_AAAA, IP, NX, NODATA
|
||||
mode: "NULL"
|
||||
# Should FTL enrich blocked replies with EDNS0 information?
|
||||
# Possible values are: "NONE", "CODE", "TEXT"
|
||||
edns: "TEXT"
|
||||
# [dns.specialDomains]
|
||||
specialDomains:
|
||||
# Should Pi-hole always reply with NXDOMAIN to A and AAAA queries of
|
||||
# use-application-dns.net to disable Firefox automatic DNS-over-HTTP?
|
||||
mozillaCanary: true
|
||||
# Should Pi-hole always reply with NXDOMAIN to A and AAAA queries of mask.icloud.com
|
||||
# and mask-h2.icloud.com to disable Apple's iCloud Private Relay to prevent Apple
|
||||
# devices from bypassing Pi-hole?
|
||||
iCloudPrivateRelay: true
|
||||
# Should Pi-hole always reply with NODATA to all queries to zone resolver.arpa to
|
||||
# prevent devices from bypassing Pi-hole using Discovery of Designated Resolvers?
|
||||
designatedResolver: true
|
||||
reply:
|
||||
# [dns.reply.host]
|
||||
host:
|
||||
# Use a specific IPv4 address for the Pi-hole host?
|
||||
force4: false
|
||||
# Custom IPv4 address for the Pi-hole host
|
||||
IPv4: ""
|
||||
# Use a specific IPv6 address for the Pi-hole host?
|
||||
force6: false
|
||||
# Custom IPv6 address for the Pi-hole host
|
||||
IPv6: ""
|
||||
# [dns.reply.blocking]
|
||||
blocking:
|
||||
# Use a specific IPv4 address in IP blocking mode?
|
||||
force4: false
|
||||
# Custom IPv4 address for IP blocking mode
|
||||
IPv4: ""
|
||||
# Use a specific IPv6 address in IP blocking mode?
|
||||
force6: false
|
||||
# Custom IPv6 address for IP blocking mode
|
||||
IPv6: ""
|
||||
# [dns.rateLimit]
|
||||
rateLimit:
|
||||
# Rate-limited queries are answered with a REFUSED reply and not further processed by FTL.
|
||||
count: 1000
|
||||
# ... in the set interval before rate-limiting?
|
||||
interval: 60
|
||||
# [dhcp]
|
||||
dhcp:
|
||||
# Is the embedded DHCP server enabled?
|
||||
active: false
|
||||
# Start address of the DHCP address pool
|
||||
start: ""
|
||||
# End address of the DHCP address pool
|
||||
end: ""
|
||||
# Address of the gateway to be used (typically the address of your router)
|
||||
router: ""
|
||||
# The netmask used by your Pi-hole.
|
||||
netmask: ""
|
||||
# If the lease time is given, then leases will be given for that length of time.
|
||||
leaseTime: ""
|
||||
# Should Pi-hole make an attempt to also satisfy IPv6 address requests
|
||||
ipv6: false
|
||||
# Enable DHCPv4 Rapid Commit Option specified in RFC 4039.
|
||||
rapidCommit: false
|
||||
# Advertise DNS server multiple times to clients.
|
||||
multiDNS: false
|
||||
# Enable logging for DHCP.
|
||||
logging: false
|
||||
# Ignore unknown DHCP clients.
|
||||
ignoreUnknownClients: false
|
||||
# Per host parameters for the DHCP server.
|
||||
hosts: []
|
||||
ntp:
|
||||
# [ntp.ipv4]
|
||||
ipv4:
|
||||
# Should FTL act as network time protocol (NTP) server (IPv4)?
|
||||
active: false
|
||||
# IPv4 address to listen on for NTP requests
|
||||
address: ""
|
||||
# [ntp.ipv6]
|
||||
ipv6:
|
||||
# Should FTL act as network time protocol (NTP) server (IPv6)?
|
||||
active: false
|
||||
address: ""
|
||||
# [ntp.sync]
|
||||
sync:
|
||||
# Should FTL try to synchronize the system time with an upstream NTP server?
|
||||
active: false
|
||||
# NTP upstream server to sync with, e.g., "pool.ntp.org". Note that the NTP server
|
||||
# should be located as close as possible to you in order to minimize the time offset
|
||||
# possibly introduced by different routing paths.
|
||||
# http://www.svl2.ntp.se
|
||||
# https://www.cyberinfo.se/arkiv/tidssynkronisering-med-ntp
|
||||
# server: "se.pool.ntp.org"
|
||||
server: "sth2.ntp.se"
|
||||
# Interval in seconds between successive synchronization attempts with the NTP server
|
||||
interval: 3600
|
||||
# Number of NTP syncs to perform and average before updating the system time
|
||||
count: 8
|
||||
# [ntp.sync.rtc]
|
||||
rtc:
|
||||
# Should FTL update a real-time clock (RTC) if available?
|
||||
set: false
|
||||
# Path to the RTC device to update. Leave empty for auto-discovery
|
||||
device: ""
|
||||
# Should the RTC be set to UTC?
|
||||
utc: true
|
||||
# [resolver]
|
||||
resolver:
|
||||
# Should FTL try to resolve IPv4 addresses to hostnames?
|
||||
resolveIPv4: true
|
||||
# Should FTL try to resolve IPv6 addresses to hostnames?
|
||||
resolveIPv6: true
|
||||
# Control whether FTL should use the fallback option to try to obtain client names from
|
||||
# checking the network table. This behavior can be disabled with this option.
|
||||
networkNames: true
|
||||
# With this option, you can change how (and if) hourly PTR requests are made to check
|
||||
# for changes in client and upstream server hostnames.
|
||||
# Possible values are: "IPV4_ONLY", "ALL", "UNKNOWN", "NONE"
|
||||
refreshNames: "IPV4_ONLY"
|
||||
# [database]
|
||||
database:
|
||||
# Should FTL load information from the database on startup to be aware of the most
|
||||
# recent history?
|
||||
DBimport: true
|
||||
# How long should queries be stored in the database [days]?
|
||||
# Setting this value to 0 will disable the database.
|
||||
maxDBdays: 91
|
||||
# How often do we store queries in FTL's database [seconds]?
|
||||
DBinterval: 60
|
||||
# Should FTL enable Write-Ahead Log (WAL) mode for the on-disk query database
|
||||
# (configured via files.database)? It is recommended to leave this setting enabled
|
||||
# for performance reasons.
|
||||
useWAL: true
|
||||
# [database.network]
|
||||
network:
|
||||
# Should FTL analyze the local ARP cache? When disabled, client identification and the
|
||||
# network table will stop working reliably.
|
||||
parseARPcache: true
|
||||
# How long should IP addresses be kept in the network_addresses table [days]? IP
|
||||
# addresses (and associated host names) older than the specified number of days are
|
||||
# removed to avoid dead entries in the network overview table.
|
||||
# looks like it should be set to the same value as database.maxDBdays
|
||||
expire: 91
|
||||
# [webserver]
|
||||
webserver:
|
||||
# On which domain is the web interface served?
|
||||
domain: "pi.hole"
|
||||
# Webserver access control list (ACL) allowing for restrictions to be put on the list
|
||||
# of IP addresses which have access to the web server.
|
||||
acl: ""
|
||||
# Ports to be used by the webserver. Comma-separated list of ports to listen on.
|
||||
# I want to make it easier on myself so set to port 80 on all interfaces for both IPv4 and IPv6
|
||||
# note that this is different from Pi-Hole's default "80o,443os,[::]:80o,[::]:443os"
|
||||
# port: "80,[::]:80" # this gives the lighttpd landing page and no Pi-Hole web UI
|
||||
# port: "80o,443os,[::]:80o,[::]:443os" # ditto
|
||||
# for some reason this works but not the variations above
|
||||
port: "8080o,8443os,[::]:8080o,[::]:8443os"
|
||||
# Maximum number of worker threads allowed.
|
||||
threads: 50
|
||||
# Additional HTTP headers added to the web server responses.
|
||||
headers:
|
||||
- "X-DNS-Prefetch-Control: off"
|
||||
- "Content-Security-Policy: default-src 'self' 'unsafe-inline';"
|
||||
- "X-Frame-Options: DENY"
|
||||
- "X-XSS-Protection: 0"
|
||||
- "X-Content-Type-Options: nosniff"
|
||||
- "Referrer-Policy: strict-origin-when-cross-origin"
|
||||
# Should the web server serve all files in webserver.paths.webroot directory?
|
||||
serve_all: false
|
||||
# [webserver.session]
|
||||
session:
|
||||
# Session timeout in seconds.
|
||||
# This option may also be used to make logins persistent for long times.
|
||||
timeout: 1800
|
||||
# Should Pi-hole backup and restore sessions from the database?
|
||||
restore: true
|
||||
# [webserver.tls]
|
||||
tls:
|
||||
# Path to the TLS (SSL) certificate file.
|
||||
cert: "/etc/pihole/tls.pem"
|
||||
# [webserver.paths]
|
||||
paths:
|
||||
# Server root on the host
|
||||
webroot: "/var/www/html"
|
||||
# Sub-directory of the root containing the web interface
|
||||
webhome: "/admin/"
|
||||
# Prefix where the web interface is served
|
||||
prefix: ""
|
||||
# [webserver.interface]
|
||||
interface:
|
||||
# Should the web interface use the boxed layout?
|
||||
boxed: true
|
||||
# Theme used by the Pi-hole web interface
|
||||
# Possible values are: "default-auto", "default-light", "default-dark", "default-darker",
|
||||
# "high-contrast", "high-contrast-dark", "lcars" (Star Trek LCARS)
|
||||
theme: "default-auto"
|
||||
# [webserver.api]
|
||||
api:
|
||||
# Number of concurrent sessions allowed for the API.
|
||||
max_sessions: 16
|
||||
# Should FTL prettify the API output (add extra spaces, newlines and indentation)?
|
||||
prettyJSON: false
|
||||
# API password hash (you set password, hash is generated in Jinja template)
|
||||
password: "{{ pihole_web_password }}"
|
||||
# Pi-hole 2FA TOTP secret.
|
||||
totp_secret: ""
|
||||
# Pi-hole application password (to circumvent 2FA for legacy 3rd-party services)
|
||||
app_password: ""
|
||||
# Should application password API sessions be allowed to modify config settings?
|
||||
app_sudo: false
|
||||
# Should FTL create a temporary CLI password? This password is stored in clear in
|
||||
# /etc/pihole and can be used by the CLI (pihole ... commands) to authenticate
|
||||
# against the API.
|
||||
cli_pw: true
|
||||
# Array of clients to be excluded from certain API responses (regex),
|
||||
# e.g., the Top Clients or Query Log
|
||||
excludeClients: []
|
||||
# Array of domains to be excluded from certain API responses (regex),
|
||||
# e.g., the Top Clients or Query Log
|
||||
excludeDomains: []
|
||||
# How much history should be imported from the database and returned by the API
|
||||
# [seconds]? (max 24*60*60 = 86400)
|
||||
maxHistory: 86400
|
||||
# Up to how many clients should be returned in the activity graph endpoint
|
||||
# (/api/history/clients)?
|
||||
# This setting can be overwritten at run-time using the parameter N. Setting this to 0
|
||||
# will always send all clients. Be aware that this may be challenging for the GUI if
|
||||
# you have many (think > 1.000 clients) in your network
|
||||
maxClients: 0 # default 10
|
||||
# How should the API compute the most active clients?
|
||||
client_history_global_max: true
|
||||
# Allow destructive API calls (e.g. restart DNS server, flush logs, ...)
|
||||
allow_destructive: true
|
||||
# [webserver.api.temp]
|
||||
temp:
|
||||
# Which upper temperature limit should be used by Pi-hole?
|
||||
limit: "60.000000"
|
||||
# Which temperature unit should be used for temperatures processed by FTL?
|
||||
unit: "C"
|
||||
# [files]
|
||||
files:
|
||||
# The file which contains the PID of FTL's main process.
|
||||
pid: "/run/pihole-FTL.pid"
|
||||
# The location of FTL's long-term database
|
||||
database: "/etc/pihole/pihole-FTL.db"
|
||||
# The location of Pi-hole's gravity database
|
||||
gravity: "/etc/pihole/gravity.db"
|
||||
# A temporary directory where Pi-hole can store files during gravity updates.
|
||||
gravity_tmp: "/tmp"
|
||||
# The database containing MAC -> Vendor information for the network table
|
||||
macvendor: "/etc/pihole/macvendor.db"
|
||||
# An optional file containing a pcap capture of the network traffic.
|
||||
pcap: ""
|
||||
# [files.log]
|
||||
log:
|
||||
# The location of FTL's log file
|
||||
ftl: "/var/log/pihole/FTL.log"
|
||||
# The log file used by the embedded dnsmasq DNS server
|
||||
dnsmasq: "/var/log/pihole/pihole.log"
|
||||
# The log file used by the webserver
|
||||
webserver: "/var/log/pihole/webserver.log"
|
||||
# [misc]
|
||||
misc:
|
||||
# Privacy levels in Pi-Hole statistics
|
||||
# Changing this setting will trigger a restart of FTL
|
||||
# - 0: don't hide anything
|
||||
# - 1: hide domains
|
||||
# - 2: hide domains and clients
|
||||
# - 3: anonymize everything
|
||||
privacylevel: 1
|
||||
delay_startup: 0
|
||||
# Set niceness of pihole-FTL. Defaults to -10 and can be disabled altogether by setting
|
||||
# a value of -999.
|
||||
nice: -10
|
||||
addr2line: true
|
||||
# Should FTL load additional dnsmasq configuration files from /etc/dnsmasq.d/?
|
||||
etc_dnsmasq_d: false
|
||||
# Either enable misc.etc_dnsmasq_d to restore the "old" behaviour, or if
|
||||
# you have only a few lines you can add them directly to the misc.dnsmasq_lines
|
||||
# setting instead. https://discourse.pi-hole.net/t/v6-post-release-fixes-and-findings/76480
|
||||
dnsmasq_lines:
|
||||
# maximum number of concurrent DNS queries, 150 by default
|
||||
# https://discourse.pi-hole.net/t/ resolved-maximum-number-of-concurrent-dns-queries-reached/60970
|
||||
# https://discourse.pi-hole.net/t/maximum-number-of-concurrent-dns-queries-reached/51804
|
||||
- "dns-forward-max=150"
|
||||
# Log additional information about queries and replies to pihole.log
|
||||
extraLogging: false
|
||||
# Put configuration into read-only mode. This will prevent any changes to the
|
||||
# configuration file via the API or CLI. This setting useful when a configuration is
|
||||
# to be forced/modified by some third-party application (like infrastructure-as-code
|
||||
# providers) and should not be changed by any means.
|
||||
# This setting is critical to allow this role to configure pihole.toml reliably
|
||||
# https://discourse.pi-hole.net/t/support-writing-to-pihole-toml-directly/70522
|
||||
# default False
|
||||
readOnly: true
|
||||
# [misc.check]
|
||||
check:
|
||||
# Have FTL regularly check system load and warn about excessive load if
|
||||
# the 15 minute system load average exceeds the number of cores?
|
||||
load: true
|
||||
shmem: 90
|
||||
# warn if disk usage exceeds this percentage (set to zero to disable)
|
||||
disk: 90
|
||||
# [debug]
|
||||
debug:
|
||||
# Print debugging information about database actions.
|
||||
database: false
|
||||
# Prints a list of the detected interfaces on the startup of pihole-FTL.
|
||||
networking: false
|
||||
# Print information about shared memory locks.
|
||||
locks: false
|
||||
# Print extensive query information (domains, types, replies, etc.).
|
||||
queries: false
|
||||
# Print flags of queries received by the DNS hooks. Only effective when DEBUG_QUERIES
|
||||
# is enabled as well.
|
||||
flags: false
|
||||
# Print information about shared memory buffers.
|
||||
shmem: false
|
||||
# Print information about garbage collection
|
||||
gc: false
|
||||
# Print information about ARP table processing
|
||||
arp: false
|
||||
# Controls if FTLDNS should print extended details about regex matching into FTL.log.
|
||||
regex: false
|
||||
# Print extra debugging information concerning API calls.
|
||||
api: false
|
||||
# Print extra debugging information about TLS connections.
|
||||
tls: false
|
||||
# Print information about overTime memory operations, such as initializing or moving
|
||||
# overTime slots.
|
||||
overtime: false
|
||||
# Print information about status changes for individual queries.
|
||||
status: false
|
||||
# Print information about capabilities granted to the pihole-FTL process.
|
||||
caps: false
|
||||
# Print information about DNSSEC activity
|
||||
dnssec: false
|
||||
# FTL uses dynamically allocated vectors for various tasks.
|
||||
vectors: false
|
||||
# Extensive information about hostname resolution like which DNS servers are used in
|
||||
# the first and second hostname resolving tries (only affecting internally generated
|
||||
# PTR queries).
|
||||
resolver: false
|
||||
# Print debugging information about received EDNS(0) data.
|
||||
edns0: false
|
||||
# Log various important client events such as change of interface (e.g., client
|
||||
# switching from WiFi to wired or VPN connection), as well as extensive reporting
|
||||
# about how clients were assigned to its groups.
|
||||
clients: false
|
||||
# Log information related to alias-client processing.
|
||||
aliasclients: false
|
||||
# Log information regarding FTL's embedded event handling queue.
|
||||
events: false
|
||||
# Log information about script helpers, e.g., due to dhcp-script.
|
||||
helper: false
|
||||
# Print config parsing details
|
||||
config: false
|
||||
# Debug monitoring of /etc/pihole filesystem events
|
||||
inotify: false
|
||||
# Debug monitoring of the webserver (CivetWeb) events
|
||||
webserver: false
|
||||
# Temporary flag that may print additional information.
|
||||
extra: false
|
||||
# Reserved debug flag
|
||||
reserved: false
|
||||
# Print information about NTP synchronization
|
||||
ntp: false
|
||||
# Print information about netlink communication and parsing
|
||||
netlink: false
|
||||
# Set all debug flags at once. This is a convenience option to enable all debug flags
|
||||
# at once. Note that this option is not persistent, setting it to true will enable all
|
||||
# *remaining* debug flags but unsetting it will disable *all* debug flags.
|
||||
all: false
|
||||
|
||||
|
||||
# Merged recursively over pihole_default. config.dns.interface must be set here.
|
||||
pihole_overrides: {}
|
||||
|
||||
# set pihole_testing to true to enable debug messages
|
||||
# easiest via --extra-vars "{pihole_testing: true}"
|
||||
# the web password, app password and TOTP secret are masked in that output
|
||||
pihole_testing: false
|
||||
pihole_testing_timeout: 5
|
||||
|
||||
# path to Pi-Hole's automated install script
|
||||
# supports the "--unattended" flag
|
||||
# NOTE the inner quotes are important since path contains a space
|
||||
# Lazy: reads __pihole_effective.repo.path, which tasks/merge-defaults.yml sets in the role.
|
||||
pihole_install_script: "'{{ __pihole_effective.repo.path }}/automated install/basic-install.sh'"
|
||||
|
||||
# available on Ubuntu noble and resolute
|
||||
pihole_apt_dependencies:
|
||||
- curl # command line tool for transferring data with URL syntax
|
||||
- git # fast, scalable, distributed revision control system
|
||||
- procps # /proc file system utilities
|
||||
- lighttpd-mod-deflate # fast webserver with minimal memory footprint
|
||||
- apt-utils # package management related utility programs
|
||||
- whiptail # Displays user-friendly dialog boxes from shell scripts
|
||||
# dropped because of incompatibility with RPi lightdm desktop environment
|
||||
# which should not affect Ubuntu, but since I have not tested that specifically
|
||||
# and since this package is not critical, safer to just drop it
|
||||
# - dhcpcd5 # DHCPv4, IPv6RA and DHCPv6 client with IPv4LL support
|
||||
- dnsutils # Transitional package for bind9-dnsutils
|
||||
- bc # GNU bc arbitrary precision calculator language
|
||||
- unzip # De-archiver for .zip files
|
||||
- wget # retrieves files from the web
|
||||
- sudo # Provide limited super user privileges to specific users
|
||||
- netcat-openbsd # TCP/IP swiss army knife
|
||||
- cron # process scheduling daemon
|
||||
- iproute2 # networking and traffic control tools
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
|
||||
# Rather than restarting the systemd job, use pihole's builtin reconfig script.
|
||||
# When you run "pihole -r", a TUI window "Existing Install Detected!" lets you
|
||||
# select either
|
||||
# + Repair: This will retain existing settings
|
||||
# + Reconfigure: Resets Pi-hole and allows re-selecting settings
|
||||
# https://old.reddit.com/r/pihole/comments/m7nx5w/run_pihole_r_unattended
|
||||
# It looks to me like "--reconfigure --unattended" and "--repair --unattended" both
|
||||
# perform the same tasks.
|
||||
- name: Reconfigure Pi-Hole subsystems
|
||||
become: true
|
||||
ansible.builtin.command: "{{ pihole_install_script }} --reconfigure --unattended"
|
||||
listen: reconfigure pihole
|
||||
changed_when: true
|
||||
@@ -0,0 +1,88 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: Install and configure Pi-hole from the upstream repository
|
||||
description:
|
||||
- >-
|
||||
Asserts an Ubuntu host and the merged settings, merges the C(pihole_overrides) dictionary over
|
||||
C(pihole_default), installs the apt dependencies, creates the C(pihole) system user, renders C(pihole.toml),
|
||||
clones the upstream repository, runs its installer in unattended mode on first install, and runs the
|
||||
installer's reconfigure mode when C(pihole.toml) changes.
|
||||
- >-
|
||||
The configuration contract is a single dictionary, C(pihole_overrides), whose keys are merged recursively
|
||||
over C(pihole_default) in C(defaults/main.yml). The spec types it as a dictionary only, because sub-options
|
||||
would reject every key it does not list. The merged result is an internal fact and never overwrites the
|
||||
input. The role fails unless the merged C(config.dns.upstreams) is a non-empty list, C(config.dns.interface)
|
||||
is a non-empty string and C(config.webserver.api.password) is a string other than
|
||||
C(changetoyourownpassword).
|
||||
- >-
|
||||
C(pihole_default) (every setting rendered into C(pihole.toml)) and C(pihole_install_script) (the quoted
|
||||
installer path under C(repo.path)) are role defaults deliberately not listed here, because argument
|
||||
validation templates every listed variable. C(pihole_install_script) reads the merged settings, which the
|
||||
role sets only after validation. Templating C(pihole_default) would turn a missing C(pihole_web_password)
|
||||
into an undefined-variable error before the clean missing-required-arguments message. Override settings
|
||||
through C(pihole_overrides) instead.
|
||||
options:
|
||||
pihole_web_password:
|
||||
type: raw
|
||||
required: true
|
||||
no_log: true
|
||||
description:
|
||||
- >-
|
||||
The Pi-hole web interface and API password, the default of the merged
|
||||
C(config.webserver.api.password). A secret: source it from a vaulted variable. Required even when
|
||||
C(pihole_overrides) sets the password, because the merge templates the whole of C(pihole_default),
|
||||
which references it.
|
||||
- The rendered C(pihole.toml) holds it hashed twice with SHA-256 (C(pwhash)).
|
||||
pihole_overrides:
|
||||
type: dict
|
||||
default: {}
|
||||
no_log: true
|
||||
description:
|
||||
- >-
|
||||
Overrides merged recursively over C(pihole_default). Specify only the keys to change. Define the whole
|
||||
dictionary in one place, because a dictionary set in two variable sources is not merged and the
|
||||
higher-precedence one wins.
|
||||
- >-
|
||||
C(config.dns.interface) must be set (string, for example C(eth0)): its default is an empty placeholder
|
||||
and the role fails until it is set. C(config.dns.upstreams) (list of IP addresses or hostnames,
|
||||
optionally with C(#port)) must stay non-empty. C(config.webserver.api.password) must stay a string.
|
||||
C(config.webserver.api.totp_secret) and C(config.webserver.api.app_password) are also credentials.
|
||||
- >-
|
||||
Other keys the tasks read are C(repo.remote), C(repo.version) (a tag, default C(v6.4)), C(repo.path)
|
||||
(default C(~/.cache/pi-hole) of the connecting user), C(user), C(group) (both default C(pihole)) and
|
||||
C(config.files.database) (its directory receives C(pihole.toml)). Every other key is rendered into
|
||||
C(pihole.toml).
|
||||
pihole_testing:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- >-
|
||||
When true the role prints the merged settings with the web password, app password and TOTP secret
|
||||
masked, pauses C(pihole_testing_timeout) seconds, and on a first install reads and prints the installer
|
||||
log.
|
||||
pihole_testing_timeout:
|
||||
type: int
|
||||
default: 5
|
||||
description:
|
||||
- Seconds to pause after the merge result is printed. Only used when C(pihole_testing) is true.
|
||||
pihole_apt_dependencies:
|
||||
type: list
|
||||
elements: str
|
||||
default:
|
||||
- curl
|
||||
- git
|
||||
- procps
|
||||
- lighttpd-mod-deflate
|
||||
- apt-utils
|
||||
- whiptail
|
||||
- dnsutils
|
||||
- bc
|
||||
- unzip
|
||||
- wget
|
||||
- sudo
|
||||
- netcat-openbsd
|
||||
- cron
|
||||
- iproute2
|
||||
description:
|
||||
- apt packages installed before the clone. Overriding replaces the whole list.
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: pihole
|
||||
namespace: mortis
|
||||
author: Taha Ahmed (solarchemist), modified by Defame1297
|
||||
license: GPL-3.0-only AND EUPL-1.2
|
||||
description: Install and configure Pi-hole v6 from the upstream repository in unattended mode, rendering pihole.toml from a merged settings dict.
|
||||
min_ansible_version: "2.22"
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- noble
|
||||
galaxy_tags:
|
||||
- pihole
|
||||
- dns
|
||||
- adblock
|
||||
dependencies: []
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# The password is overridden, but pihole_web_password is still required: pihole_default
|
||||
# references it.
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
vars:
|
||||
pihole_web_password: not-used
|
||||
pihole_overrides: "{{ pihole_test_overrides }}"
|
||||
roles:
|
||||
- role: mortis.kamino.pihole
|
||||
@@ -0,0 +1,63 @@
|
||||
---
|
||||
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image
|
||||
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Needs outbound network for the apt packages. The upstream
|
||||
# Pi-hole repository is replaced by a local stub whose installer only logs its arguments
|
||||
# (prepare.yml), so the scenario tests the role's own logic, not Pi-hole itself.
|
||||
# The containers run systemd as PID 1 with a writable cgroup; no privileged mode.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: ${KAMINO_RUN_ID:-local}-pihole-noble
|
||||
labels:
|
||||
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
|
||||
image: ${MOLECULE_IMAGE}
|
||||
pre_build_image: true
|
||||
pull: true
|
||||
command: /sbin/init
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
tmpfs:
|
||||
- /run
|
||||
- /run/lock
|
||||
security_opts:
|
||||
- apparmor=unconfined
|
||||
provisioner:
|
||||
name: ansible
|
||||
# One source for every play, so the converge and the negative tests in verify.yml start from
|
||||
# the same valid input.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
pihole_test_overrides:
|
||||
repo:
|
||||
remote: file:///opt/pihole-stub.git
|
||||
config:
|
||||
dns:
|
||||
# not eth0, so verify proves the variable reaches pihole.toml
|
||||
interface: molecule0
|
||||
upstreams:
|
||||
- 9.9.9.9
|
||||
- 149.112.112.112
|
||||
webserver:
|
||||
api:
|
||||
password: molecule-test-password
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the
|
||||
# containers as soon as this scenario ends; after a local run, run `molecule destroy` yourself),
|
||||
# plus two check steps: one before the converge (first-run preview), one after the idempotence run.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- check
|
||||
- converge
|
||||
- idempotence
|
||||
- check
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
# The role clones the upstream Pi-hole repository and runs its installer, which needs a real
|
||||
# DNS stack (pihole-FTL, port 53, the gravity database). A container cannot honestly test that,
|
||||
# so the clone target is a local git repository whose installer is a stub that logs its
|
||||
# arguments and creates the database file the role checks for an existing install.
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Install git
|
||||
ansible.builtin.apt:
|
||||
name: git
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Build the stub upstream repository
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
set -e
|
||||
rm -rf /opt/pihole-stub /opt/pihole-stub.git /var/log/pihole-stub-installer.log
|
||||
mkdir -p "/opt/pihole-stub/automated install"
|
||||
cat > "/opt/pihole-stub/automated install/basic-install.sh" <<'STUB'
|
||||
#!/bin/sh
|
||||
echo "$*" >> /var/log/pihole-stub-installer.log
|
||||
mkdir -p /etc/pihole
|
||||
touch /etc/pihole/pihole-FTL.db
|
||||
STUB
|
||||
chmod 0755 "/opt/pihole-stub/automated install/basic-install.sh"
|
||||
cd /opt/pihole-stub
|
||||
git init -q -b main
|
||||
git -c user.name=molecule -c user.email=molecule@localhost add -A
|
||||
git -c user.name=molecule -c user.email=molecule@localhost commit -q -m stub
|
||||
git tag v6.4
|
||||
git clone -q --bare /opt/pihole-stub /opt/pihole-stub.git
|
||||
executable: /bin/bash
|
||||
changed_when: true
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# One failing run: runs the role with the inputs of the case and asserts that the expected
|
||||
# message, not something else, stopped it. Input: pihole_test_case (name, overrides, expect);
|
||||
# the web password is always set here, so the validation under test is the first to fail.
|
||||
- name: "Run the role, case {{ pihole_test_case.name }}"
|
||||
block:
|
||||
- name: "Include the role, case {{ pihole_test_case.name }}"
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pihole
|
||||
vars:
|
||||
pihole_web_password: not-used
|
||||
pihole_overrides: "{{ pihole_test_case.overrides }}"
|
||||
|
||||
# Only reached when the include returned. The message must not contain the expected
|
||||
# text, so the rescue below cannot mistake it for the failure under test.
|
||||
- name: "Fail because the include returned, case {{ pihole_test_case.name }}"
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted the input
|
||||
rescue:
|
||||
- name: "The expected failure stopped the run, case {{ pihole_test_case.name }}"
|
||||
ansible.builtin.assert:
|
||||
that: pihole_test_case.expect in (ansible_failed_result.msg | default(''))
|
||||
fail_msg: "Expected '{{ pihole_test_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
|
||||
quiet: true
|
||||
@@ -0,0 +1,169 @@
|
||||
---
|
||||
# Runs first, before any play gathers facts: the role refuses a host it cannot identify as
|
||||
# Ubuntu, before any change.
|
||||
- name: Refuse a host without Ubuntu facts
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role without gathered facts
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pihole_test_case:
|
||||
name: no-facts
|
||||
overrides: "{{ pihole_test_overrides }}"
|
||||
expect: pihole supports Ubuntu only
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
# The role defaults, for the clone path and version the converge used: the scenario overrides
|
||||
# neither, so the override falls back to them. Only the leaves read below are templated.
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
vars:
|
||||
pihole_test_repo_path: "{{ pihole_test_overrides.repo.path | default(pihole_default.repo.path) }}"
|
||||
pihole_test_repo_version: "{{ pihole_test_overrides.repo.version | default(pihole_default.repo.version) }}"
|
||||
tasks:
|
||||
- name: Read the rendered pihole.toml
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/pihole/pihole.toml
|
||||
register: pihole_test_toml
|
||||
|
||||
- name: Stat pihole.toml
|
||||
ansible.builtin.stat:
|
||||
path: /etc/pihole/pihole.toml
|
||||
register: pihole_test_toml_stat
|
||||
|
||||
- name: Stat the configuration directory
|
||||
ansible.builtin.stat:
|
||||
path: /etc/pihole
|
||||
register: pihole_test_config_dir
|
||||
|
||||
# The git module only checks out; it cannot report which tag HEAD is at.
|
||||
- name: Read the tag the clone is checked out at
|
||||
ansible.builtin.command: # noqa: command-instead-of-module
|
||||
cmd: git -C {{ pihole_test_repo_path | quote }} describe --tags --exact-match HEAD
|
||||
register: pihole_test_clone_tag
|
||||
changed_when: false
|
||||
|
||||
- name: Read the stub installer log
|
||||
ansible.builtin.slurp:
|
||||
src: /var/log/pihole-stub-installer.log
|
||||
register: pihole_test_installer_log
|
||||
|
||||
- name: Look up the pihole user
|
||||
ansible.builtin.getent:
|
||||
database: passwd
|
||||
key: pihole
|
||||
|
||||
- name: The config carries the overridden upstreams and a hashed password
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'9.9.9.9' in pihole_test_toml_content"
|
||||
- "'149.112.112.112' in pihole_test_toml_content"
|
||||
- "'1.1.1.1' not in pihole_test_toml_content"
|
||||
- pihole_test_toml_content is search('(?m)^\\s*interface = \"molecule0\"')
|
||||
- "'\"eth0\"' not in pihole_test_toml_content"
|
||||
- "'molecule-test-password' not in pihole_test_toml_content"
|
||||
- pihole_test_toml_content is search('(?m)^\\s*pwhash = \"[0-9a-f]{64}\"')
|
||||
quiet: true
|
||||
vars:
|
||||
pihole_test_toml_content: "{{ pihole_test_toml.content | b64decode }}"
|
||||
|
||||
- name: The config belongs to the pihole user, group-writable
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pihole_test_toml_stat.stat.pw_name == 'pihole'
|
||||
- pihole_test_toml_stat.stat.gr_name == 'pihole'
|
||||
- pihole_test_toml_stat.stat.mode == '0664'
|
||||
quiet: true
|
||||
|
||||
- name: The configuration directory belongs to the pihole user and group, mode 0755
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pihole_test_config_dir.stat.isdir
|
||||
- pihole_test_config_dir.stat.pw_name == 'pihole'
|
||||
- pihole_test_config_dir.stat.gr_name == 'pihole'
|
||||
- pihole_test_config_dir.stat.mode == '0755'
|
||||
quiet: true
|
||||
|
||||
# The stub repository tags its only commit with the default repo.version (prepare.yml).
|
||||
- name: The clone is checked out at the configured version
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pihole_test_clone_tag.stdout == pihole_test_repo_version
|
||||
fail_msg: "Clone at {{ pihole_test_clone_tag.stdout }}, expected {{ pihole_test_repo_version }}"
|
||||
quiet: true
|
||||
|
||||
- name: The user is a system account without a login shell
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- getent_passwd.pihole[5] == '/usr/sbin/nologin'
|
||||
- getent_passwd.pihole[1] | int < 1000
|
||||
quiet: true
|
||||
|
||||
# Neither check run (before and after the converge) ran the installer or the handler.
|
||||
- name: The installer ran once, then the reconfigure handler ran it again
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pihole_test_installer_log_text.splitlines() == ['--unattended', '--reconfigure --unattended']
|
||||
quiet: true
|
||||
vars:
|
||||
pihole_test_installer_log_text: "{{ pihole_test_installer_log.content | b64decode }}"
|
||||
|
||||
# Negative tests: each validation stops the role before any change.
|
||||
- name: Refuse invalid inputs
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Run the role without pihole_web_password
|
||||
block:
|
||||
- name: Include the role without pihole_web_password
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pihole
|
||||
vars:
|
||||
pihole_overrides: "{{ pihole_test_overrides }}"
|
||||
|
||||
- name: Fail because the include returned
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted the input
|
||||
rescue:
|
||||
- name: The argument spec, not something else, stopped the run
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'missing required arguments' in (ansible_failed_result.msg | default(''))"
|
||||
- "'pihole_web_password' in (ansible_failed_result.msg | default(''))"
|
||||
fail_msg: "Got: {{ ansible_failed_result.msg | default('') }}"
|
||||
quiet: true
|
||||
|
||||
- name: Run each failing case
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
loop_control:
|
||||
loop_var: pihole_test_case
|
||||
label: "{{ pihole_test_case.name }}"
|
||||
loop:
|
||||
# no interface key: this also fails if a role default for the interface is reintroduced
|
||||
- name: interface-unset
|
||||
overrides:
|
||||
config:
|
||||
dns: {upstreams: [9.9.9.9]}
|
||||
webserver: {api: {password: molecule-test-password}}
|
||||
expect: config.dns.interface is empty
|
||||
- name: upstreams-empty
|
||||
overrides:
|
||||
config:
|
||||
dns: {interface: molecule0, upstreams: []}
|
||||
webserver: {api: {password: molecule-test-password}}
|
||||
expect: upstreams must be a non-empty list
|
||||
- name: password-not-string
|
||||
overrides:
|
||||
config:
|
||||
dns: {interface: molecule0}
|
||||
webserver: {api: {password: 12345}}
|
||||
expect: password must be a string
|
||||
- name: password-placeholder
|
||||
overrides:
|
||||
config:
|
||||
dns: {interface: molecule0}
|
||||
webserver: {api: {password: changetoyourownpassword}}
|
||||
expect: placeholder changetoyourownpassword
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
# For the unattended install to work as intended (i.e., unattended) pihole.toml must be in
|
||||
# place *before* the installer runs, so the role creates the pihole user and group itself.
|
||||
|
||||
- name: Create system user and group (nologin shell) for {{ __pihole_effective.user }}
|
||||
become: true
|
||||
ansible.builtin.user:
|
||||
name: "{{ __pihole_effective.user }}"
|
||||
state: present
|
||||
system: true
|
||||
shell: /usr/sbin/nologin
|
||||
|
||||
# this task requires the __pihole_effective.user user/group to exist, fails otherwise
|
||||
- name: Create Pi-Hole configuration directory
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
name: "{{ __pihole_effective.config.files.database | dirname }}"
|
||||
state: directory
|
||||
owner: "{{ __pihole_effective.user }}"
|
||||
group: "{{ __pihole_effective.group }}"
|
||||
mode: '0755'
|
||||
|
||||
- name: Prepare Pi-Hole configuration (first-time installation)
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: pihole.toml.j2
|
||||
dest: "{{ __pihole_effective.config.files.database | dirname }}/pihole.toml"
|
||||
owner: "{{ __pihole_effective.user }}"
|
||||
group: "{{ __pihole_effective.group }}"
|
||||
mode: '0644'
|
||||
when:
|
||||
- not (__pihole_installed | bool)
|
||||
- not ansible_check_mode or __pihole_config_dir.stat.exists
|
||||
notify: reconfigure pihole
|
||||
# the rendered file holds the password hashes and the TOTP secret
|
||||
no_log: true
|
||||
diff: false
|
||||
@@ -0,0 +1,77 @@
|
||||
---
|
||||
|
||||
# Here I use "dependencies" in a loosely defined fashion
|
||||
# most of these packages would already be expected to be installed on any Ubuntu system
|
||||
# but, does not hurt to be thorough
|
||||
- name: Install dependencies (apt packages)
|
||||
become: true
|
||||
ansible.builtin.apt:
|
||||
name: "{{ pihole_apt_dependencies }}"
|
||||
state: present
|
||||
|
||||
# https://github.com/gsemet/ansible-rpi-pihole/blob/master/roles/pi/tasks/main.yml
|
||||
# https://gist.github.com/bendews/e09edfc60e581ec4c686c4b70297f543
|
||||
# https://github.com/Freekers/automated-pihole/blob/master/playbook.yml
|
||||
|
||||
# After reading up a little, it seems clear that the regular Pi-Hole
|
||||
# install script will not work with Ansible by default.
|
||||
# And in several places, I've seen the pihole devs state thay they don't intend
|
||||
# to support Ansible playbooks. Fair enough. I've found suggested work-arounds:
|
||||
# https://github.com/drew-kun/ansible-pihole/blob/master/tasks/install.yml
|
||||
# https://discourse.pi-hole.net/t/automated-installation-enhancements-and-fixes/28746
|
||||
# https://github.com/pi-hole/pi-hole/pull/3195
|
||||
|
||||
- name: "Clone the Pi-Hole repo"
|
||||
ansible.builtin.git:
|
||||
repo: "{{ __pihole_effective.repo.remote }}"
|
||||
dest: "{{ __pihole_effective.repo.path }}"
|
||||
version: "{{ __pihole_version }}"
|
||||
become: true
|
||||
become_user: "{{ ansible_facts['user_id'] }}"
|
||||
|
||||
|
||||
# what happens if we run the install script with a pre-existing pihole on the system?
|
||||
# is it overwritten without complaints from the installer?
|
||||
# what if the repo has an older version than the installed pihole?
|
||||
# would it perhaps by easiest to never allow install script to run if pihole is already installed?
|
||||
# on my machine the install script produced a never-ending output of "y" lines immediately after
|
||||
# successfully restarting the pihole-FTL service (if output was printed to file it quickly
|
||||
# filled the available disk space). Did this happen because Pi-Hole was already installed?
|
||||
# Only on a first install: on an installed Pi-hole the role leaves upgrades alone.
|
||||
- name: Run Pi-Hole installation script in unattended mode
|
||||
when: not (__pihole_installed | bool)
|
||||
block:
|
||||
|
||||
# the unattended install only works if pihole.toml already exists (configure.yml)
|
||||
# debug tip: keep track of the install progress by tailing the log-file on the host in question
|
||||
- name: Run Pi-Hole installation script
|
||||
become: true
|
||||
ansible.builtin.shell: >
|
||||
{{ pihole_install_script }} --unattended >>
|
||||
{{ __pihole_effective.repo.path }}/pihole_install.log
|
||||
changed_when: true
|
||||
|
||||
# can we create a task that tails -f the log file and then quits (continues to next task)
|
||||
# once no new tail output for X seconds?
|
||||
# https://stackoverflow.com/questions/33663357/how-to-continuously-tail-remote-files-using-ansible
|
||||
# https://github.com/ansible/ansible/issues/4870
|
||||
# https://github.com/ansible/ansible/issues/3887
|
||||
# https://github.com/ansible/proposals/issues/92
|
||||
# Perhaps in lieu of tailing we could simply print pihole_install.log in the next task?
|
||||
- name: Ingest the Pi-Hole install log file
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ __pihole_effective.repo.path }}/pihole_install.log"
|
||||
register: __pihole_install_log
|
||||
# under --check the installer was skipped, so there is no log to read
|
||||
when:
|
||||
- pihole_testing | bool
|
||||
- not ansible_check_mode
|
||||
|
||||
# https://www.shellhacks.com/ansible-cat-file-print-read-file-content
|
||||
- name: Display the install log
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ __pihole_install_log.content | b64decode }}"
|
||||
when:
|
||||
- pihole_testing | bool
|
||||
- not ansible_check_mode
|
||||
# END OF BLOCK
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
# Validation first, under always, so a bad input fails before any change whatever tags the
|
||||
# run selects.
|
||||
- name: Validate the role inputs
|
||||
ansible.builtin.import_tasks: validate.yml
|
||||
tags: [always, assert]
|
||||
|
||||
# Fact-only, under always: every later task reads the merged settings, so skipping a tag
|
||||
# must not skip the merge.
|
||||
- name: Merge configuration defaults
|
||||
ansible.builtin.import_tasks: merge-defaults.yml
|
||||
tags: always
|
||||
|
||||
- name: Set Pi-Hole version variable
|
||||
ansible.builtin.set_fact:
|
||||
__pihole_version: "{{ __pihole_effective.repo.version }}"
|
||||
|
||||
# Fact-only, under always: the configuration and installation tasks read it.
|
||||
- name: Check if Pi-Hole is already installed
|
||||
ansible.builtin.stat:
|
||||
path: "{{ __pihole_effective.config.files.database }}"
|
||||
register: __pihole_database
|
||||
tags: always
|
||||
|
||||
- name: Set Pi-Hole installation status
|
||||
ansible.builtin.set_fact:
|
||||
__pihole_installed: "{{ __pihole_database.stat.exists | default(false) }}"
|
||||
tags: always
|
||||
|
||||
# Read by the template tasks: under --check the directory is not created, so on a first run
|
||||
# there is no directory to render pihole.toml into. Under always, because one reader is
|
||||
# untagged and the other tagged config-only.
|
||||
- name: Check whether the Pi-Hole configuration directory exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ __pihole_effective.config.files.database | dirname }}"
|
||||
register: __pihole_config_dir
|
||||
tags: always
|
||||
|
||||
- name: Configure Pi-Hole
|
||||
ansible.builtin.import_tasks: configure.yml
|
||||
|
||||
- name: Install Pi-Hole
|
||||
ansible.builtin.import_tasks: install.yml
|
||||
|
||||
- name: Reconfigure Pi-Hole
|
||||
ansible.builtin.import_tasks: reconfigure.yml
|
||||
tags: config-only
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
# "pihole_overrides" is only read here: the merged result goes into the fact
|
||||
# "__pihole_effective", so the input is never overwritten and every run recomputes the merge.
|
||||
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/combine_filter.html
|
||||
- name: Merge overrides over the default variable
|
||||
ansible.builtin.set_fact:
|
||||
__pihole_effective: "{{ pihole_default | combine(pihole_overrides | default({}), recursive=True) }}"
|
||||
# the merged settings hold the web password
|
||||
no_log: true
|
||||
|
||||
# the web password, app password and TOTP secret are masked so the dump is
|
||||
# safe to paste into an issue or leave in CI logs
|
||||
- name: Inspect the merged settings (secrets masked)
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ __pihole_effective | combine({'config': {'webserver': {'api': __pihole_masked_secrets}}}, recursive=True) }}"
|
||||
vars:
|
||||
__pihole_masked_secrets: {password: <masked>, app_password: <masked>, totp_secret: <masked>}
|
||||
when: pihole_testing | bool
|
||||
|
||||
- name: Pausing to highlight merge result
|
||||
ansible.builtin.wait_for:
|
||||
timeout: "{{ pihole_testing_timeout }}"
|
||||
when: pihole_testing | bool
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
|
||||
- name: Configure pihole.toml
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: pihole.toml.j2
|
||||
# rather than hard-code /etc/pihole ourselves we can ride on the coat-tails
|
||||
# of any of the __pihole_effective.config.files vars
|
||||
dest: "{{ __pihole_effective.config.files.database | dirname }}/pihole.toml"
|
||||
owner: "{{ __pihole_effective.user }}"
|
||||
group: "{{ __pihole_effective.group }}"
|
||||
mode: '0664'
|
||||
when: not ansible_check_mode or __pihole_config_dir.stat.exists
|
||||
notify: reconfigure pihole
|
||||
# the rendered file holds the password hashes and the TOTP secret
|
||||
no_log: true
|
||||
diff: false
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
|
||||
# change. pihole_web_password is required by the argument spec, which runs before this file.
|
||||
|
||||
# The role also reads gathered facts (env.HOME, user_id), so a run without
|
||||
# them fails here too.
|
||||
- name: Require Ubuntu
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts['distribution'] | default('') == 'Ubuntu'
|
||||
fail_msg: >-
|
||||
pihole supports Ubuntu only (found: {{ ansible_facts['distribution'] | default('no gathered facts') }}).
|
||||
The role reads gathered facts, so run it in a play that gathers them.
|
||||
quiet: true
|
||||
|
||||
# The merge is computed here as well as in merge-defaults.yml, so these checks run before
|
||||
# anything else, on every tag selection.
|
||||
- name: Check the merged Pi-hole settings
|
||||
vars:
|
||||
__pihole_candidate: "{{ pihole_default | combine(pihole_overrides | default({}), recursive=True) }}"
|
||||
block:
|
||||
- name: Check that at least one upstream DNS server is defined
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __pihole_candidate.config.dns.upstreams is defined
|
||||
- __pihole_candidate.config.dns.upstreams | length > 0
|
||||
fail_msg: pihole_overrides.config.dns.upstreams must be a non-empty list of upstream DNS servers.
|
||||
quiet: true
|
||||
|
||||
- name: Check that the DNS interface is set
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __pihole_candidate.config.dns.interface is string
|
||||
- __pihole_candidate.config.dns.interface | trim | length > 0
|
||||
fail_msg: >-
|
||||
The merged config.dns.interface is empty. Set it through the pihole_overrides dictionary
|
||||
(for example pihole_overrides.config.dns.interface: eth0); there is no role default.
|
||||
quiet: true
|
||||
|
||||
- name: Check that the web password is a string
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __pihole_candidate.config.webserver.api.password is defined
|
||||
- __pihole_candidate.config.webserver.api.password is string
|
||||
fail_msg: The merged config.webserver.api.password must be a string.
|
||||
quiet: true
|
||||
|
||||
- name: Check that the web password has been changed from the placeholder
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __pihole_candidate.config.webserver.api.password != "changetoyourownpassword"
|
||||
fail_msg: >-
|
||||
The web password is the placeholder changetoyourownpassword: set pihole_web_password, or
|
||||
pihole_overrides.config.webserver.api.password, to a secret of your own.
|
||||
quiet: true
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,108 @@
|
||||
# pve_lxc
|
||||
|
||||
Creates and maintains a Proxmox VE LXC container through the Proxmox API: configuration, root disk size, raw `lxc.*` config lines, an opt-in guest firewall file and the power state. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
|
||||
|
||||
## Supported platforms
|
||||
|
||||
Proxmox VE nodes on Debian 13 (trixie). The play runs for the container's inventory host: the API calls run on the controller (`delegate_to: localhost`), and the raw config, the guest firewall file and the filesystem resize run on the Proxmox node (`delegate_to: pve_lxc_node`) with become.
|
||||
|
||||
Untested platforms: Debian trixie, as declared in `meta/main.yml`. The molecule scenario runs the node-side tasks in an Ubuntu 24.04 (noble) container standing in for the node (see [Tests](#tests)); a Debian test image does not exist yet.
|
||||
|
||||
The role targets Proxmox nodes only, so it does not cover Ubuntu noble or resolute: Proxmox VE runs on Debian.
|
||||
|
||||
## Requirements and run order
|
||||
|
||||
- Use it by its fully qualified name, `mortis.kamino.pve_lxc`, in a play over the container hosts. It gathers no facts and needs none.
|
||||
- The controller needs the `community.proxmox` collection and the Python library `proxmoxer`.
|
||||
- Role dependencies: none.
|
||||
- `pve_lxc_node` must be an inventory host: the node-side tasks are delegated to it, and its `ansible_host` is the default API address. `pve_lxc_api_user` and `pve_lxc_api_token_secret` have no usable default and are asserted non-empty before any change when `pve_lxc_manage_lifecycle` is true; `pve_lxc_net_prefix` too, unless `pve_lxc_state` is `absent`. The raw config and firewall inputs are validated at the same point.
|
||||
- The container's own `ansible_host` is its address in `net0` and the target of the SSH wait, and `inventory_hostname` is its hostname.
|
||||
- Run it before any role that configures the inside of the container. Gate those on `pve_lxc_present` (below), so a container that is absent is not configured.
|
||||
|
||||
## Role variables
|
||||
|
||||
No variable is marked required in the argument spec: with `pve_lxc_manage_lifecycle: false` the role reads none of the Proxmox inputs.
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `pve_lxc_state` | `present` | `present`, `started`, `stopped` or `absent`. `present` leaves the power state alone. |
|
||||
| `pve_lxc_manage_lifecycle` | `true` | False skips everything and treats the container as present (a container on a node Ansible does not manage). |
|
||||
| `pve_lxc_allow_destroy` | `false` | Required before `absent` deletes the container. |
|
||||
| `pve_lxc_wait_for_ssh` | `true` | Wait for SSH on port 22 of `ansible_host` when `started`. |
|
||||
| `pve_lxc_manage_disk` | `false` | Grow the root disk to the size in `pve_lxc_disk`. |
|
||||
| `pve_lxc_reboot_if_required` | `true` | Restart the container after its root filesystem was grown. |
|
||||
| `pve_lxc_pubkey` | `""` | Public keys for root, one per line. |
|
||||
| `pve_lxc_features` | `[]` | Container features, for example `nesting=1`. Omitted when empty. |
|
||||
| `pve_lxc_restart_on_config_change` | `false` | Restart after a configuration update reports a change. |
|
||||
| `pve_lxc_cmode` | `tty` | Console mode sent on update. |
|
||||
| `pve_lxc_raw_config` | `[]` | Raw `lxc.*` lines, one per item. See Notes. |
|
||||
| `pve_lxc_onboot` | `true` | Start on node boot, for `started` and `present`. A `stopped` container always gets `onboot=0`. |
|
||||
| `pve_lxc_node`, `pve_lxc_vmid` | none | Inventory name of the Proxmox node and container id. |
|
||||
| `pve_lxc_ostemplate` | none | Template volume, for example `local:vztmpl/<template>.tar.zst`. Read on creation only. |
|
||||
| `pve_lxc_disk` | none | Root disk as `<storage>:<size in GB>`. |
|
||||
| `pve_lxc_memory` | none | Memory in MB. |
|
||||
| `pve_lxc_cores`, `pve_lxc_swap`, `pve_lxc_nameserver` | none | Omitted when undefined. |
|
||||
| `pve_lxc_net` | none | Mapping with `bridge`, `gw` and `tag`, used to build `net0`. |
|
||||
| `pve_lxc_net_interface` | `eth0` | Interface name in `net0`. |
|
||||
| `pve_lxc_net_prefix` | `""` (asserted) | Prefix length (1 to 32) of `ansible_host` in `net0`. Environment-specific, so it has no real default. |
|
||||
| `pve_lxc_api_user` | `""` (asserted) | API user without realm; `@<pve_lxc_api_realm>` is appended. |
|
||||
| `pve_lxc_api_realm` | `pam` | Realm of the API user. |
|
||||
| `pve_lxc_api_token_id` | `<pve_lxc_api_user>-token` | API token id. |
|
||||
| `pve_lxc_api_token_secret` | none (asserted) | API token secret, normally vaulted. No default. `no_log`. |
|
||||
| `pve_lxc_api_host` | `ansible_host` of `pve_lxc_node`, empty without it | Proxmox API address (port 8006). |
|
||||
| `pve_lxc_firewall` | `false` | Opt-in guest firewall: `firewall=1` on `net0` and `/etc/pve/firewall/<vmid>.fw`. See Notes. |
|
||||
| `pve_lxc_firewall_policy_in`, `pve_lxc_firewall_policy_out` | `DROP` | Policy for unmatched traffic: `ACCEPT`, `DROP` or `REJECT`. |
|
||||
| `pve_lxc_firewall_rules` | `[]` | Proxmox rule lines, in order, first match wins, each starting with `IN` or `OUT` and `ACCEPT`, `DROP` or `REJECT`. |
|
||||
|
||||
The `pve_lxc_api_*` inputs are applied through `module_defaults` inside the block that holds every API call of the role, and the `uri` calls send the header `PVEAPIToken=<user>@<realm>!<token_id>=<secret>`, derived in `vars/main.yml`.
|
||||
|
||||
## Variables set by the role
|
||||
|
||||
- `pve_lxc_exists`: the container exists on the node.
|
||||
- `pve_lxc_present`: the container exists and `pve_lxc_state` is not `absent`. With `pve_lxc_manage_lifecycle: false` both are `true`.
|
||||
|
||||
## Tags
|
||||
|
||||
The input validation (`tasks/validate.yml`) carries `always`, so it runs whatever tags are selected. No other task is tagged, so only a play-level tag applies to them.
|
||||
|
||||
## Example play
|
||||
|
||||
```yaml
|
||||
- name: Provision containers
|
||||
hosts: containers
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: mortis.kamino.pve_lxc
|
||||
vars:
|
||||
pve_lxc_state: started
|
||||
pve_lxc_node: pve1
|
||||
pve_lxc_vmid: 120
|
||||
pve_lxc_ostemplate: local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst
|
||||
pve_lxc_disk: local-lvm:8
|
||||
pve_lxc_memory: 1024
|
||||
pve_lxc_net:
|
||||
bridge: vmbr0
|
||||
gw: 192.0.2.1
|
||||
tag: 20
|
||||
pve_lxc_net_prefix: 24
|
||||
pve_lxc_manage_disk: true
|
||||
pve_lxc_api_user: ansible
|
||||
pve_lxc_api_token_secret: "{{ vault_pve_api_token_secret }}"
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
The `default` molecule scenario runs in CI on Ubuntu 24.04 (noble), the `molecule-ubuntu2404` image, which stands in for the Proxmox node. The API lifecycle (detect, create, update, resize, start, stop, delete and the restarts) is not exercised: there is no Proxmox API in the scenario. The converge includes the internal task files `main.yml` runs on the node side, in its order (`validate`, `firewall`, `raw_config`), with `pve_lxc_state: stopped`, under which the role never restarts the container. Prepare seeds a container config with stale `lxc.*` lines, blockinfile markers and a snapshot section, and backup copies of two containers' configs. Verify checks the reconciled config byte for byte (Proxmox's lines kept in order, the desired `lxc.*` lines after them, the snapshot section untouched), the rendered firewall file, and that only this container's backups were removed. It runs `check` before the converge and after the idempotence run. Negative tests cover a state outside the spec, missing API credentials and a missing network prefix through `main`, and raw config given as a string, outside the `lxc.` namespace or with two lines in one item, a malformed firewall rule and an unknown policy through `validate`; a run with `pve_lxc_manage_lifecycle: false` checks the presence facts. No Proxmox service runs, so pmxcfs's handling of the files and `pve-firewall` loading the rules are not verified.
|
||||
|
||||
## Notes
|
||||
|
||||
- Idempotent: yes for the node-side files, which the scenario checks; the API update relies on `community.proxmox` reporting no change, which is not tested.
|
||||
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check` the creation is skipped, so a container that does not exist yet is not updated or configured in that run; `pve_lxc_raw_config` is still validated.
|
||||
- Raw config: `pve_lxc_raw_config` owns the whole `lxc.*` namespace of the main section of `/etc/pve/lxc/<vmid>.conf`. Other `lxc.*` lines, including hand-written ones, are removed, and an empty list removes them all. Each item must be one line starting with `lxc.`. Order counts. Snapshot sections are never edited. A change restarts the container unless `pve_lxc_state` is `stopped`, independent of `pve_lxc_restart_on_config_change`. Ansible backup copies of the file (`<vmid>.conf.*~`) are removed.
|
||||
- Disk: the disk only grows. When `pve_lxc_manage_disk` is true and `pve_lxc_disk` is larger, the role resizes through the API, fails if Proxmox did not apply it, runs `pct resize` on the node and restarts the container when `pve_lxc_reboot_if_required` is true.
|
||||
- `net0` is `name=<pve_lxc_net_interface>,bridge=<bridge>,ip=<ansible_host>/<pve_lxc_net_prefix>,gw=<gw>,tag=<tag>`, plus `,firewall=1` only when `pve_lxc_firewall` is true.
|
||||
- The container is created without a root password: root gets only `pve_lxc_pubkey`.
|
||||
- Guest firewall: for a container whose root cannot be trusted, a firewall inside it is useless, so the Proxmox firewall on the node filters its `net0`. With `pve_lxc_firewall: true` the role writes `/etc/pve/firewall/<vmid>.fw` on the node before the container is created (`pve-firewall` reloads it by itself) with `enable: 1`, `ipfilter: 1` (the container cannot use another address than its `net0` one), `macfilter: 1`, the two policies and the rules. False leaves `net0` and the firewall files untouched; a file written earlier stays but is inert, since the NIC loses its firewall flag. Proxmox skips a rule line it cannot parse, so the role only checks each line's shape; prove the syntax with `pve-firewall compile` on the node.
|
||||
- The guest rules filter only while the datacenter firewall is enabled (`/etc/pve/firewall/cluster.fw`, `enable: 1`), which the role does not manage. Enabling it with Proxmox's defaults sets the nodes' input policy to DROP and allows only SSH and port 8006 from the cluster network, which can lock out the controller. A way to enable it with host traffic unfiltered: keep a node console open; on every node create `/etc/pve/nodes/<node>/host.fw` with `[OPTIONS]` and `enable: 0`; then create `cluster.fw` with `[OPTIONS]`, `enable: 1`, `policy_in: ACCEPT`, `policy_out: ACCEPT`. Check `pve-firewall status` on each node. Enabling it also sends bridged traffic of guests without a firewall through the `PVEFW-FORWARD` chain, which drops conntrack-invalid packets. Roll back with `enable: 0` in `cluster.fw`.
|
||||
- TLS certificates of the API are not verified.
|
||||
- `no_log` is set on every task that carries the API token.
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
pve_lxc_state: present # present | started | stopped | absent
|
||||
pve_lxc_manage_disk: false # disk resizing is explicit
|
||||
pve_lxc_wait_for_ssh: true
|
||||
pve_lxc_allow_destroy: false
|
||||
# false = the LXC lives on a Proxmox node Ansible does not manage; skip the
|
||||
# lifecycle tasks and treat the guest as present so it is still configured.
|
||||
pve_lxc_manage_lifecycle: true
|
||||
pve_lxc_onboot: true
|
||||
# Restart the container after its root filesystem was grown.
|
||||
pve_lxc_reboot_if_required: true
|
||||
|
||||
pve_lxc_pubkey: ""
|
||||
|
||||
# e.g. ["nesting=1", "keyctl=1"] to allow Docker/nested containers inside
|
||||
# an unprivileged LXC. See https://pve.proxmox.com/wiki/Linux_Container#pct_options.
|
||||
pve_lxc_features: []
|
||||
|
||||
# Proxmox applies some changes (features) only on the next start. Off by default, so routine
|
||||
# config drift (netif, nameserver ...) does not restart guests.
|
||||
pve_lxc_restart_on_config_change: false
|
||||
|
||||
pve_lxc_raw_config: []
|
||||
|
||||
# Console mode sent on update (tasks/update.yml says why it is sent explicitly).
|
||||
pve_lxc_cmode: tty
|
||||
|
||||
# Proxmox API credentials. Only read when the LXC lifecycle is managed
|
||||
# (pve_lxc_manage_lifecycle true); tasks/validate.yml then asserts that the user and
|
||||
# the token secret are set. The user is the bare name: the role appends
|
||||
# @<pve_lxc_api_realm>. The token secret, pve_lxc_api_token_secret, is a secret
|
||||
# input with no default, normally vaulted.
|
||||
pve_lxc_api_user: ""
|
||||
pve_lxc_api_realm: pam
|
||||
pve_lxc_api_token_id: "{{ pve_lxc_api_user }}-token"
|
||||
# The Proxmox node's address. Guarded so the default templates to '' (and the
|
||||
# argument validation passes) on a host without pve_lxc_node.
|
||||
pve_lxc_api_host: "{{ hostvars[pve_lxc_node].ansible_host if pve_lxc_node is defined else '' }}"
|
||||
|
||||
# Container network interface name.
|
||||
pve_lxc_net_interface: eth0
|
||||
# Prefix length of ansible_host in net0. Environment-specific, so there is no
|
||||
# real default: empty here, asserted in tasks/validate.yml.
|
||||
pve_lxc_net_prefix: ""
|
||||
|
||||
# Proxmox guest firewall on net0, opt-in. Off: net0 carries no firewall flag
|
||||
# and no /etc/pve/firewall/<vmid>.fw is written, so other containers are unchanged.
|
||||
# The rules only filter while the datacenter firewall is enabled (README).
|
||||
pve_lxc_firewall: false
|
||||
pve_lxc_firewall_policy_in: DROP
|
||||
pve_lxc_firewall_policy_out: DROP
|
||||
# Proxmox rule lines, evaluated in order, e.g. "IN ACCEPT -source 192.0.2.5 -p tcp -dport 22".
|
||||
pve_lxc_firewall_rules: []
|
||||
@@ -0,0 +1,227 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: Manage a Proxmox LXC container
|
||||
description:
|
||||
- >-
|
||||
Detects the container through the Proxmox API, validates C(pve_lxc_raw_config), deletes the container when C(pve_lxc_state)
|
||||
is absent and C(pve_lxc_allow_destroy) is true, otherwise creates it when missing, updates its configuration and disk,
|
||||
reconciles the raw C(lxc.*) lines in C(/etc/pve/lxc/<vmid>.conf), applies the power state and waits for SSH when
|
||||
the container is started.
|
||||
- >-
|
||||
When C(pve_lxc_manage_lifecycle) is false the role only sets C(pve_lxc_exists) and C(pve_lxc_present) to true and does nothing
|
||||
else, so none of the Proxmox inputs below is read. This is how a container on a node Ansible does not manage is
|
||||
handled.
|
||||
- >-
|
||||
API calls run on localhost and authenticate with C(pve_lxc_api_user) (bare user name, C(@<pve_lxc_api_realm>) is
|
||||
appended), C(pve_lxc_api_token_id), C(pve_lxc_api_token_secret) and C(pve_lxc_api_host), applied through
|
||||
C(module_defaults), and with the header C(PVEAPIToken=<user>@<realm>!<token_id>=<secret>) for the C(uri) calls,
|
||||
which the role derives from them in C(vars/main.yml) (internal, not an input).
|
||||
The user and the token secret have no usable default: they are asserted non-empty in the input validation,
|
||||
only for a container with C(pve_lxc_manage_lifecycle) true. The caller sets them.
|
||||
The raw config, disk filesystem resize and the C(pct) call are delegated to C(pve_lxc_node) with become.
|
||||
C(community.proxmox) and, on the controller, the Python library C(proxmoxer) must be installed. TLS certificates
|
||||
are not verified.
|
||||
- >-
|
||||
Also reads C(ansible_host) (container address and SSH wait), C(inventory_hostname) (container hostname) and
|
||||
C(ansible_check_mode). The role sets the facts C(pve_lxc_exists) and C(pve_lxc_present) for later plays. C(pve_lxc_present) is
|
||||
true only while the container exists and C(pve_lxc_state) is not absent.
|
||||
options:
|
||||
pve_lxc_state:
|
||||
type: str
|
||||
default: present
|
||||
choices: [present, started, stopped, absent]
|
||||
description:
|
||||
- >-
|
||||
C(present) keeps the container configured without touching its power state. C(started) and C(stopped) also
|
||||
apply the power state, and C(started) additionally waits for SSH when C(pve_lxc_wait_for_ssh) is true. C(absent)
|
||||
deletes the container, but only when C(pve_lxc_allow_destroy) is true.
|
||||
pve_lxc_manage_lifecycle:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
When false the container is treated as present and every lifecycle task is skipped. Set it for containers on
|
||||
a node Ansible does not manage.
|
||||
pve_lxc_allow_destroy:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- Safety switch required before C(pve_lxc_state=absent) deletes the container.
|
||||
pve_lxc_wait_for_ssh:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- When true and C(pve_lxc_state) is started, wait for SSH on port 22 of C(ansible_host).
|
||||
pve_lxc_manage_disk:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- >-
|
||||
Allow the root disk to be grown to the size in C(pve_lxc_disk). Growing fails the play when Proxmox does not apply it,
|
||||
and runs C(pct resize) on C(pve_lxc_node).
|
||||
pve_lxc_pubkey:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- Public keys installed for root by the container creation and update, one per line.
|
||||
pve_lxc_features:
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
description:
|
||||
- >-
|
||||
Proxmox container features such as C(nesting=1) or C(keyctl=1). Omitted when empty. Proxmox applies a change
|
||||
only on the next start, and lets an API user other than C(root@pam) change only some of them, such as
|
||||
C(nesting).
|
||||
pve_lxc_restart_on_config_change:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- Restart the container when the configuration update reports a change. Off by default so routine drift does not restart guests.
|
||||
pve_lxc_cmode:
|
||||
type: str
|
||||
default: tty
|
||||
description:
|
||||
- Console mode sent on update. Sent explicitly because community.proxmox 2.0.0 otherwise forwarded a value Proxmox rejects.
|
||||
pve_lxc_raw_config:
|
||||
type: raw
|
||||
default: []
|
||||
description:
|
||||
- >-
|
||||
Raw C(lxc.*) lines for the container config, one per list item, each a single line starting with C(lxc.).
|
||||
The role default is an empty list. Anything that is not a list of such strings fails the play, except an empty
|
||||
or null value, which is treated as an empty list and removes every C(lxc.*) line that is present. The
|
||||
validation also runs in check mode on a container that does not exist yet. A change restarts the container (outside
|
||||
check mode, unless C(pve_lxc_state) is stopped), independent of C(pve_lxc_restart_on_config_change).
|
||||
pve_lxc_onboot:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
Start the container when the node boots, for a container whose C(pve_lxc_state) is C(started) or C(present).
|
||||
A C(stopped) container always gets C(onboot=0), whatever this says, so a node reboot does not start it.
|
||||
Sent on create and on update.
|
||||
pve_lxc_reboot_if_required:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- Restart the container after its root filesystem was grown.
|
||||
pve_lxc_node:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
Inventory name of the Proxmox host that runs the container. Must be a host in the inventory; its
|
||||
C(ansible_host) is the default of C(pve_lxc_api_host). Not read when C(pve_lxc_manage_lifecycle) is false.
|
||||
pve_lxc_vmid:
|
||||
type: int
|
||||
description:
|
||||
- Container id on the Proxmox node. Not read when C(pve_lxc_manage_lifecycle) is false.
|
||||
pve_lxc_ostemplate:
|
||||
type: str
|
||||
description:
|
||||
- Template volume the container is created from, for example C(local:vztmpl/<template>.tar.zst). Only read on creation.
|
||||
pve_lxc_disk:
|
||||
type: raw
|
||||
description:
|
||||
- >-
|
||||
Root disk as C(<storage>:<size in GB>), for example C(local-lvm:8). The number after the last colon is the
|
||||
desired size in GB. Only read on creation, on update and for disk detection.
|
||||
pve_lxc_memory:
|
||||
type: raw
|
||||
description:
|
||||
- Memory in MB. Read on creation and on update.
|
||||
pve_lxc_cores:
|
||||
type: raw
|
||||
description:
|
||||
- CPU cores. Omitted when undefined.
|
||||
pve_lxc_swap:
|
||||
type: raw
|
||||
description:
|
||||
- Swap in MB. Omitted when undefined.
|
||||
pve_lxc_nameserver:
|
||||
type: str
|
||||
description:
|
||||
- Nameserver for the container. Omitted when undefined.
|
||||
pve_lxc_net:
|
||||
type: raw
|
||||
description:
|
||||
- >-
|
||||
Mapping with C(bridge), C(gw) and C(tag). The role builds C(net0) from it as
|
||||
C(name=<pve_lxc_net_interface>,bridge=<bridge>,ip=<ansible_host>/<pve_lxc_net_prefix>,gw=<gw>,tag=<tag>),
|
||||
plus C(,firewall=1) when C(pve_lxc_firewall) is true.
|
||||
pve_lxc_firewall:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- >-
|
||||
Opt-in Proxmox guest firewall. When true, C(firewall=1) is appended to C(net0) and
|
||||
C(/etc/pve/firewall/<vmid>.fw) is written on C(pve_lxc_node) before the container is created, with
|
||||
C(enable), C(ipfilter) and C(macfilter) on, the two policies and C(pve_lxc_firewall_rules). When false
|
||||
neither is touched, so C(net0) is unchanged; a file written earlier is left in place but inert, since
|
||||
the NIC no longer has the firewall flag. The rules only filter while the datacenter firewall is enabled.
|
||||
pve_lxc_firewall_policy_in:
|
||||
type: str
|
||||
default: DROP
|
||||
choices: [ACCEPT, DROP, REJECT]
|
||||
description:
|
||||
- Policy for inbound traffic that no rule matches.
|
||||
pve_lxc_firewall_policy_out:
|
||||
type: str
|
||||
default: DROP
|
||||
choices: [ACCEPT, DROP, REJECT]
|
||||
description:
|
||||
- Policy for outbound traffic that no rule matches.
|
||||
pve_lxc_firewall_rules:
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
description:
|
||||
- >-
|
||||
Proxmox firewall rule lines, evaluated in order, first match wins, each a single line starting with
|
||||
C(IN) or C(OUT) and C(ACCEPT), C(DROP) or C(REJECT), for example C(IN ACCEPT -source 192.0.2.5 -p tcp -dport 22).
|
||||
Only the shape is checked; Proxmox skips a line it cannot parse.
|
||||
pve_lxc_api_user:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Proxmox API user, the bare name without realm (C(@<pve_lxc_api_realm>) is appended). Required when
|
||||
C(pve_lxc_manage_lifecycle) is true: the role asserts it is non-empty before any change.
|
||||
pve_lxc_api_realm:
|
||||
type: str
|
||||
default: pam
|
||||
description:
|
||||
- Authentication realm of C(pve_lxc_api_user), appended as C(@<realm>) in C(module_defaults) and in the C(uri) header.
|
||||
pve_lxc_api_token_id:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
API token id, without the user part. Role default C(<pve_lxc_api_user>-token), a Jinja expression in
|
||||
C(defaults/main.yml), so it is not repeated here.
|
||||
pve_lxc_api_token_secret:
|
||||
type: str
|
||||
no_log: true
|
||||
description:
|
||||
- >-
|
||||
API token secret, normally vaulted. No default. Required when C(pve_lxc_manage_lifecycle) is true: the role
|
||||
asserts it is set and non-empty before any change. Every task that carries it is C(no_log).
|
||||
pve_lxc_api_host:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
Address of the Proxmox API (port 8006). Role default the C(ansible_host) of C(pve_lxc_node), or empty when
|
||||
C(pve_lxc_node) is undefined; a Jinja expression in C(defaults/main.yml), so it is not repeated here.
|
||||
pve_lxc_net_interface:
|
||||
type: str
|
||||
default: eth0
|
||||
description:
|
||||
- Name of the container network interface in C(net0).
|
||||
pve_lxc_net_prefix:
|
||||
type: raw
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Prefix length (1 to 32) appended to C(ansible_host) in C(net0). Environment-specific, so the empty default
|
||||
is a placeholder: the role fails with a clear message while it is unset and the LXC lifecycle is managed
|
||||
with C(pve_lxc_state) other than C(absent).
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: pve_lxc
|
||||
namespace: mortis
|
||||
author: Defame1297
|
||||
license: GPL-3.0-or-later
|
||||
description: Manage Proxmox VE LXC containers through the Proxmox API, with raw lxc.* config lines and a guest firewall file on the node.
|
||||
min_ansible_version: "2.22"
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- trixie
|
||||
galaxy_tags:
|
||||
- proxmox
|
||||
- lxc
|
||||
- container
|
||||
- provisioning
|
||||
dependencies: []
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
# The validation and the node-side task files only, in main.yml's order: main.yml would also call the
|
||||
# Proxmox API to detect the container, which the scenario does not exercise (README, Tests).
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Validate the inputs
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pve_lxc
|
||||
tasks_from: validate
|
||||
|
||||
- name: Write the guest firewall file
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pve_lxc
|
||||
tasks_from: firewall
|
||||
|
||||
- name: Reconcile the raw config lines
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pve_lxc
|
||||
tasks_from: raw_config
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image
|
||||
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). The container stands in for the
|
||||
# Proxmox node: the role's node-side task files (raw config reconcile, guest firewall file) and
|
||||
# its input validation run against it. Nothing calls the Proxmox API (README, Tests).
|
||||
# The container runs systemd as PID 1 with a writable cgroup; no privileged mode.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: ${KAMINO_RUN_ID:-local}-pve-lxc-instance
|
||||
labels:
|
||||
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
|
||||
image: ${MOLECULE_IMAGE}
|
||||
pre_build_image: true
|
||||
pull: true
|
||||
command: /sbin/init
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
tmpfs:
|
||||
- /run
|
||||
- /run/lock
|
||||
security_opts:
|
||||
- apparmor=unconfined
|
||||
provisioner:
|
||||
name: ansible
|
||||
# One source for every play, so the converge and the negative tests in verify.yml start from
|
||||
# the same valid input.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
pve_lxc_node: "{{ inventory_hostname }}"
|
||||
pve_lxc_vmid: 9100
|
||||
# The docker connection sets no ansible_host, from which the role defaults the API address;
|
||||
# argument validation templates that default, so main would fail on it instead.
|
||||
pve_lxc_api_host: 192.0.2.1
|
||||
# Valid inputs for validate.yml; a negative case empties the one under test.
|
||||
pve_lxc_api_user: molecule
|
||||
pve_lxc_api_token_secret: not-a-secret
|
||||
pve_lxc_net_prefix: 24
|
||||
# stopped: the role never restarts a stopped container, so the raw config change makes
|
||||
# no API call.
|
||||
pve_lxc_state: stopped
|
||||
pve_lxc_raw_config:
|
||||
- "lxc.cgroup2.devices.allow: c 226:0 rwm"
|
||||
- "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir 0 0"
|
||||
- "lxc.mount.entry: /srv/data srv/data none bind,create=dir 0 0"
|
||||
pve_lxc_firewall: true
|
||||
# not the defaults, so verify proves the variables reach the file
|
||||
pve_lxc_firewall_policy_in: REJECT
|
||||
pve_lxc_firewall_policy_out: ACCEPT
|
||||
pve_lxc_firewall_rules:
|
||||
- IN ACCEPT -source 192.0.2.10 -p tcp -dport 22
|
||||
- OUT DROP -dest 198.51.100.0/24
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends; after a local run, run `molecule destroy` yourself),
|
||||
# plus two check steps: one before the converge (first-run preview), one after the idempotence run.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- check
|
||||
- converge
|
||||
- idempotence
|
||||
- check
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
# Seeds the node-side files the converge reconciles: a container config with stale lxc.* lines,
|
||||
# blockinfile markers of an earlier block and a snapshot section, plus backup copies of this
|
||||
# container's config and of another one's.
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Create the Proxmox config directories
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
loop:
|
||||
- /etc/pve/lxc
|
||||
- /etc/pve/firewall
|
||||
|
||||
- name: Seed the container config
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/pve/lxc/9100.conf
|
||||
mode: "0640"
|
||||
content: |
|
||||
#molecule test container
|
||||
arch: amd64
|
||||
cores: 1
|
||||
lxc.cgroup2.devices.allow: c 10:200 rwm
|
||||
# BEGIN ANSIBLE MANAGED BLOCK (lxc_raw_config)
|
||||
lxc.mount.entry: /srv/old srv/old none bind,create=dir 0 0
|
||||
# END ANSIBLE MANAGED BLOCK (lxc_raw_config)
|
||||
memory: 512
|
||||
net0: name=eth0,bridge=vmbr0,ip=192.0.2.20/24,gw=192.0.2.1
|
||||
rootfs: local-lvm:vm-9100-disk-0,size=8G
|
||||
|
||||
[before-upgrade]
|
||||
arch: amd64
|
||||
lxc.mount.entry: /srv/snap srv/snap none bind,create=dir 0 0
|
||||
memory: 512
|
||||
|
||||
- name: Seed backup copies of two container configs
|
||||
ansible.builtin.copy:
|
||||
dest: "/etc/pve/lxc/{{ item }}"
|
||||
mode: "0640"
|
||||
content: "stale\n"
|
||||
loop:
|
||||
- "9100.conf.1234.2026-01-01@00:00:00~"
|
||||
- "9101.conf.1234.2026-01-01@00:00:00~"
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
# One failing run: includes the role's task file named by the case, with the inputs the caller
|
||||
# sets on the include, and asserts that the expected message, not something else, stopped it.
|
||||
# Input: pve_lxc_test_case (name, tasks_from, expect).
|
||||
- name: "Run the role, case {{ pve_lxc_test_case.name }}"
|
||||
block:
|
||||
- name: "Include the role, case {{ pve_lxc_test_case.name }}"
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pve_lxc
|
||||
tasks_from: "{{ pve_lxc_test_case.tasks_from }}"
|
||||
|
||||
# Only reached when the include returned. The message must not contain the expected
|
||||
# text, so the rescue below cannot mistake it for the failure under test.
|
||||
- name: "Fail because the include returned, case {{ pve_lxc_test_case.name }}"
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted the input
|
||||
rescue:
|
||||
- name: "The expected failure stopped the run, case {{ pve_lxc_test_case.name }}"
|
||||
ansible.builtin.assert:
|
||||
that: pve_lxc_test_case.expect in (ansible_failed_result.msg | default(''))
|
||||
fail_msg: "Expected '{{ pve_lxc_test_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
|
||||
quiet: true
|
||||
@@ -0,0 +1,175 @@
|
||||
---
|
||||
# The refusal cases run first: each fails before any change, so the file assertions after them
|
||||
# also show the node unchanged by them.
|
||||
- name: Refuse invalid input
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse a state outside the argument spec choices
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_state: running
|
||||
pve_lxc_test_case:
|
||||
name: state-choice
|
||||
tasks_from: main
|
||||
expect: pve_lxc_state must be one of
|
||||
|
||||
- name: Refuse a managed lifecycle without API credentials
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_api_user: ""
|
||||
pve_lxc_test_case:
|
||||
name: no-credentials
|
||||
tasks_from: main
|
||||
expect: The Proxmox API calls need pve_lxc_api_user
|
||||
|
||||
- name: Refuse a managed lifecycle without an API token secret
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_api_token_secret: ""
|
||||
pve_lxc_test_case:
|
||||
name: no-token-secret
|
||||
tasks_from: main
|
||||
expect: The Proxmox API calls need pve_lxc_api_user
|
||||
|
||||
- name: Refuse a managed lifecycle without a network prefix
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_net_prefix: ""
|
||||
pve_lxc_test_case:
|
||||
name: no-prefix
|
||||
tasks_from: main
|
||||
expect: pve_lxc_net_prefix must be the subnet prefix length
|
||||
|
||||
- name: Refuse raw config given as a string
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_raw_config: "lxc.mount.entry: /srv/a srv/a none bind 0 0"
|
||||
pve_lxc_test_case:
|
||||
name: raw-config-string
|
||||
tasks_from: validate
|
||||
expect: pve_lxc_raw_config must be a YAML list of strings
|
||||
|
||||
- name: Refuse a raw config line outside the lxc. namespace
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_raw_config:
|
||||
- "memory: 1024"
|
||||
pve_lxc_test_case:
|
||||
name: raw-config-prefix
|
||||
tasks_from: validate
|
||||
expect: "Offending entries: ['memory: 1024']"
|
||||
|
||||
- name: Refuse a raw config item holding two lines
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_raw_config:
|
||||
- "lxc.mount.entry: /srv/a srv/a none bind 0 0\nlxc.mount.entry: /srv/b srv/b none bind 0 0"
|
||||
pve_lxc_test_case:
|
||||
name: raw-config-newline
|
||||
tasks_from: validate
|
||||
expect: Offending entries
|
||||
|
||||
- name: Refuse a firewall rule of the wrong shape
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_firewall_rules:
|
||||
- ACCEPT IN -p tcp -dport 22
|
||||
pve_lxc_test_case:
|
||||
name: firewall-rule
|
||||
tasks_from: validate
|
||||
expect: single-line Proxmox rules
|
||||
|
||||
- name: Refuse a firewall policy outside ACCEPT, DROP and REJECT
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
pve_lxc_firewall_policy_in: ALLOW
|
||||
pve_lxc_test_case:
|
||||
name: firewall-policy
|
||||
tasks_from: validate
|
||||
expect: must be ACCEPT, DROP or REJECT
|
||||
|
||||
- name: Treat a container on an unmanaged node as present
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role with the lifecycle unmanaged
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.pve_lxc
|
||||
vars:
|
||||
pve_lxc_manage_lifecycle: false
|
||||
|
||||
- name: Assert the presence facts
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pve_lxc_exists
|
||||
- pve_lxc_present
|
||||
quiet: true
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
# Proxmox's own lines first, in order, then the desired lxc.* lines, then the snapshot
|
||||
# section byte for byte: no stale lxc.* line and no marker left.
|
||||
pve_lxc_test_expected_config: |
|
||||
#molecule test container
|
||||
arch: amd64
|
||||
cores: 1
|
||||
memory: 512
|
||||
net0: name=eth0,bridge=vmbr0,ip=192.0.2.20/24,gw=192.0.2.1
|
||||
rootfs: local-lvm:vm-9100-disk-0,size=8G
|
||||
|
||||
lxc.cgroup2.devices.allow: c 226:0 rwm
|
||||
lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir 0 0
|
||||
lxc.mount.entry: /srv/data srv/data none bind,create=dir 0 0
|
||||
[before-upgrade]
|
||||
arch: amd64
|
||||
lxc.mount.entry: /srv/snap srv/snap none bind,create=dir 0 0
|
||||
memory: 512
|
||||
pve_lxc_test_expected_firewall: |
|
||||
[OPTIONS]
|
||||
enable: 1
|
||||
ipfilter: 1
|
||||
macfilter: 1
|
||||
policy_in: REJECT
|
||||
policy_out: ACCEPT
|
||||
|
||||
[RULES]
|
||||
IN ACCEPT -source 192.0.2.10 -p tcp -dport 22
|
||||
OUT DROP -dest 198.51.100.0/24
|
||||
tasks:
|
||||
- name: Read the container config
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/pve/lxc/9100.conf
|
||||
register: pve_lxc_test_config
|
||||
|
||||
- name: Assert the raw config lines were reconciled
|
||||
ansible.builtin.assert:
|
||||
that: (pve_lxc_test_config.content | b64decode) == pve_lxc_test_expected_config
|
||||
fail_msg: "Unexpected config: {{ pve_lxc_test_config.content | b64decode }}"
|
||||
quiet: true
|
||||
|
||||
- name: Read the guest firewall file
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/pve/firewall/9100.fw
|
||||
register: pve_lxc_test_firewall
|
||||
|
||||
- name: Assert the guest firewall file
|
||||
ansible.builtin.assert:
|
||||
that: (pve_lxc_test_firewall.content | b64decode) == pve_lxc_test_expected_firewall
|
||||
fail_msg: "Unexpected firewall file: {{ pve_lxc_test_firewall.content | b64decode }}"
|
||||
quiet: true
|
||||
|
||||
- name: Find the config backups left
|
||||
ansible.builtin.find:
|
||||
paths: /etc/pve/lxc
|
||||
patterns: "*~"
|
||||
register: pve_lxc_test_backups
|
||||
|
||||
- name: Assert only the other container's backup is left
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pve_lxc_test_backups.files | map(attribute='path') | map('basename') | list
|
||||
== ['9101.conf.1234.2026-01-01@00:00:00~']
|
||||
quiet: true
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
- name: Create LXC if it does not exist
|
||||
# No root password: root gets only the keys in pve_lxc_pubkey.
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
ostemplate: "{{ pve_lxc_ostemplate }}"
|
||||
disk: "{{ pve_lxc_disk }}"
|
||||
memory: "{{ pve_lxc_memory }}"
|
||||
cores: "{{ pve_lxc_cores | default(omit) }}"
|
||||
swap: "{{ pve_lxc_swap | default(omit) }}"
|
||||
nameserver: "{{ pve_lxc_nameserver | default(omit) }}"
|
||||
netif:
|
||||
net0: >-
|
||||
{{ (['name=' ~ pve_lxc_net_interface, 'bridge=' ~ pve_lxc_net.bridge,
|
||||
'ip=' ~ ansible_host ~ '/' ~ pve_lxc_net_prefix, 'gw=' ~ pve_lxc_net.gw,
|
||||
'tag=' ~ pve_lxc_net.tag] + (['firewall=1'] if pve_lxc_firewall | bool else []))
|
||||
| join(',') }}
|
||||
pubkey: "{{ pve_lxc_pubkey }}"
|
||||
features: "{{ pve_lxc_features if (pve_lxc_features | length > 0) else omit }}"
|
||||
onboot: "{{ __pve_lxc_effective_onboot }}"
|
||||
state: present
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
- name: Stop LXC before deletion (if running)
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
state: stopped
|
||||
when:
|
||||
- pve_lxc_exists
|
||||
- not ansible_check_mode
|
||||
|
||||
- name: Delete LXC
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
state: absent
|
||||
when:
|
||||
- pve_lxc_exists
|
||||
- not ansible_check_mode
|
||||
register: __pve_lxc_delete
|
||||
|
||||
- name: Update LXC presence after deletion
|
||||
ansible.builtin.set_fact:
|
||||
pve_lxc_present: false
|
||||
when:
|
||||
- __pve_lxc_delete is defined
|
||||
- __pve_lxc_delete.changed
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
- name: Check if LXC exists
|
||||
no_log: true # Authorization header carries the API token
|
||||
delegate_to: localhost
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ pve_lxc_api_host }}:8006/api2/json/nodes/{{ pve_lxc_node }}/lxc/{{ pve_lxc_vmid }}/config"
|
||||
method: GET
|
||||
headers:
|
||||
Authorization: "{{ __pve_lxc_api_auth_header }}"
|
||||
status_code: [200, 404, 500]
|
||||
register: __pve_lxc_config
|
||||
check_mode: false
|
||||
|
||||
- name: Set LXC existence fact
|
||||
ansible.builtin.set_fact:
|
||||
pve_lxc_exists: "{{ __pve_lxc_config.status == 200 }}"
|
||||
|
||||
- name: Set public LXC presence API
|
||||
ansible.builtin.set_fact:
|
||||
pve_lxc_present: "{{ pve_lxc_exists and pve_lxc_state != 'absent' }}"
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
- name: Get current LXC config
|
||||
no_log: true # Authorization header carries the API token
|
||||
delegate_to: localhost
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ pve_lxc_api_host }}:8006/api2/json/nodes/{{ pve_lxc_node }}/lxc/{{ pve_lxc_vmid }}/config"
|
||||
method: GET
|
||||
headers:
|
||||
Authorization: "{{ __pve_lxc_api_auth_header }}"
|
||||
register: __pve_lxc_config
|
||||
when: pve_lxc_exists
|
||||
|
||||
- name: Extract rootfs string
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_rootfs_str: "{{ __pve_lxc_config.json.data.rootfs | default('') }}"
|
||||
|
||||
- name: Extract current disk number and unit properly
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_disk_parts: "{{ __pve_lxc_rootfs_str | regex_findall('size=(\\d+)([GM])') | first | default(['0', 'G']) | list }}"
|
||||
|
||||
- name: Extract current disk number
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_current_disk_number: "{{ __pve_lxc_disk_parts[0] | int }}"
|
||||
__pve_lxc_current_disk_unit: "{{ __pve_lxc_disk_parts[1] }}"
|
||||
|
||||
- name: Convert current disk size to GB
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_current_disk: "{{ __pve_lxc_current_disk_number if __pve_lxc_current_disk_unit == 'G' else (__pve_lxc_current_disk_number / 1024) }}"
|
||||
|
||||
- name: Extract desired disk size (GB)
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_desired_disk_size: "{{ (pve_lxc_disk.split(':')[-1] | int) }}"
|
||||
|
||||
- name: Determine if disk resize is needed
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_resize_disk: "{{ __pve_lxc_desired_disk_size | int > __pve_lxc_current_disk | int }}"
|
||||
when: pve_lxc_exists
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
# Written before the container is created, so its rules exist before net0 first comes up with
|
||||
# firewall=1; pve-firewall picks up the change by itself. pmxcfs refuses a chmod to any mode but
|
||||
# 0640, and template cannot create a new file there (its atomic move chmods the 0600 staging file).
|
||||
# Over an existing file it keeps that file's 0640, so the file is created empty first: touch is a
|
||||
# plain open(), and preserving the timestamps keeps it idempotent. Mode omitted: pmxcfs sets it.
|
||||
- name: Create the guest firewall config file # noqa: risky-file-permissions
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "/etc/pve/firewall/{{ pve_lxc_vmid }}.fw"
|
||||
state: touch
|
||||
modification_time: preserve
|
||||
access_time: preserve
|
||||
|
||||
- name: Write the guest firewall config # noqa: risky-file-permissions
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: firewall.fw.j2
|
||||
dest: "/etc/pve/firewall/{{ pve_lxc_vmid }}.fw"
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
# Validation first, under always, so a bad input fails before any change whatever tags the run
|
||||
# selects.
|
||||
- name: Validate the role inputs
|
||||
ansible.builtin.import_tasks: validate.yml
|
||||
tags: always
|
||||
|
||||
- name: Treat externally hosted LXC as present
|
||||
ansible.builtin.set_fact:
|
||||
pve_lxc_exists: true
|
||||
pve_lxc_present: true
|
||||
when: not pve_lxc_manage_lifecycle | bool
|
||||
|
||||
# Every Proxmox API call of the role is inside this block, so the credentials are set once here
|
||||
# and never read when pve_lxc_manage_lifecycle is false (validate.yml asserts them otherwise). The uri tasks (detect, detect_disk) take
|
||||
# host and header explicitly.
|
||||
- name: Manage Proxmox LXC lifecycle
|
||||
when: pve_lxc_manage_lifecycle | bool
|
||||
module_defaults:
|
||||
community.proxmox.proxmox:
|
||||
api_user: "{{ pve_lxc_api_user }}@{{ pve_lxc_api_realm }}"
|
||||
api_token_id: "{{ pve_lxc_api_token_id }}"
|
||||
api_token_secret: "{{ pve_lxc_api_token_secret }}"
|
||||
api_host: "{{ pve_lxc_api_host }}"
|
||||
validate_certs: false
|
||||
ansible.builtin.uri:
|
||||
validate_certs: false
|
||||
block:
|
||||
- name: Detect LXC existence
|
||||
ansible.builtin.include_tasks: detect.yml
|
||||
|
||||
- name: Delete LXC (explicit)
|
||||
ansible.builtin.include_tasks: delete.yml
|
||||
when:
|
||||
- pve_lxc_state == "absent"
|
||||
- pve_lxc_allow_destroy | bool
|
||||
- pve_lxc_exists
|
||||
|
||||
- name: Abort play after deletion
|
||||
ansible.builtin.meta: end_host
|
||||
when:
|
||||
- pve_lxc_state == "absent"
|
||||
- pve_lxc_allow_destroy | bool
|
||||
- pve_lxc_exists
|
||||
|
||||
- name: Detect disk size (only if exists)
|
||||
ansible.builtin.include_tasks: detect_disk.yml
|
||||
when:
|
||||
- pve_lxc_exists
|
||||
- pve_lxc_state != "absent"
|
||||
|
||||
- name: Manage the guest firewall
|
||||
ansible.builtin.include_tasks: firewall.yml
|
||||
when:
|
||||
- pve_lxc_state != "absent"
|
||||
- pve_lxc_firewall | bool
|
||||
|
||||
- name: Create LXC (only if missing)
|
||||
ansible.builtin.include_tasks: create.yml
|
||||
when:
|
||||
- pve_lxc_state != "absent"
|
||||
- not pve_lxc_exists
|
||||
- not ansible_check_mode
|
||||
|
||||
# Gated on the existence detected before the create, so a container created in this run is
|
||||
# first updated on the next run.
|
||||
- name: Update LXC (only if exists)
|
||||
ansible.builtin.include_tasks: update.yml
|
||||
when:
|
||||
- pve_lxc_state != "absent"
|
||||
- pve_lxc_exists
|
||||
|
||||
# A create that did not fail leaves the container existing: set the facts locally, so the raw
|
||||
# config below is applied in the same run without another API call.
|
||||
- name: Mark LXC as existing after creation
|
||||
ansible.builtin.set_fact:
|
||||
pve_lxc_exists: true
|
||||
pve_lxc_present: true
|
||||
when:
|
||||
- pve_lxc_state != "absent"
|
||||
- not pve_lxc_exists
|
||||
- not ansible_check_mode
|
||||
|
||||
# Not gated on pve_lxc_raw_config being non-empty: an emptied list must still remove the
|
||||
# lxc.* lines an earlier run wrote. Gated on existence: no config file exists before the
|
||||
# container does.
|
||||
- name: Apply raw LXC config lines
|
||||
ansible.builtin.include_tasks: raw_config.yml
|
||||
when:
|
||||
- pve_lxc_state != "absent"
|
||||
- pve_lxc_exists
|
||||
|
||||
- name: Detect LXC existence
|
||||
ansible.builtin.include_tasks: detect.yml
|
||||
|
||||
- name: Ensure LXC runtime state
|
||||
ansible.builtin.include_tasks: state.yml
|
||||
when:
|
||||
- pve_lxc_state in ["started", "stopped"]
|
||||
|
||||
- name: Wait for SSH
|
||||
ansible.builtin.include_tasks: wait.yml
|
||||
when:
|
||||
- pve_lxc_state == "started"
|
||||
- pve_lxc_wait_for_ssh
|
||||
@@ -0,0 +1,114 @@
|
||||
---
|
||||
# Reconciles the raw lxc.* lines of /etc/pve/lxc/<vmid>.conf with pve_lxc_raw_config.
|
||||
#
|
||||
# A blockinfile marker block does not work here: when Proxmox re-saves the file it folds bare "#"
|
||||
# lines into the container's description, so the markers vanish and every run would insert the
|
||||
# block again, duplicating the lines and restarting the container. Instead the role owns the whole
|
||||
# "lxc." namespace, which no Proxmox-managed property uses (arch, cores, memory, net0, rootfs ...):
|
||||
# the lines of the main section are split into lxc.* lines and the rest, and when the lxc.* lines
|
||||
# differ from the desired list, in content or order, the file is rewritten in one copy with the
|
||||
# other lines first, in their order, and the desired list after them. lxc.* lines written by hand
|
||||
# or by another tool are therefore removed. Marker lines of an earlier blockinfile block
|
||||
# ("# BEGIN/END ANSIBLE MANAGED BLOCK (lxc_raw_config)") are removed in the same rewrite.
|
||||
#
|
||||
# Snapshot sections ("[name]" headers, each with its own copy of the config) are kept byte for
|
||||
# byte after the main section: a stored snapshot is never edited.
|
||||
|
||||
- name: Slurp raw LXC config file
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.slurp:
|
||||
src: "/etc/pve/lxc/{{ pve_lxc_vmid }}.conf"
|
||||
register: __pve_lxc_raw_config_slurp
|
||||
|
||||
- name: Split raw LXC config file into lines
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_raw_config_lines: "{{ (__pve_lxc_raw_config_slurp.content | b64decode).splitlines() }}"
|
||||
# default(..., true): an explicit null or "" becomes [], as in validate.yml.
|
||||
__pve_lxc_raw_config_desired: "{{ pve_lxc_raw_config | default([], true) }}"
|
||||
|
||||
- name: Determine end of main config section (before first PVE snapshot header)
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_raw_config_main_section_end: >-
|
||||
{%- set ns = namespace(idx=-1) -%}
|
||||
{%- for line in __pve_lxc_raw_config_lines -%}
|
||||
{%- if ns.idx == -1 and (line is match(__pve_lxc_raw_config_section_header_pattern)) -%}
|
||||
{%- set ns.idx = loop.index0 -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{{ __pve_lxc_raw_config_lines | length if ns.idx == -1 else ns.idx }}
|
||||
|
||||
- name: Split main config section from any PVE snapshot sections
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_raw_config_main_lines: "{{ __pve_lxc_raw_config_lines[: (__pve_lxc_raw_config_main_section_end | int)] }}"
|
||||
__pve_lxc_raw_config_snapshot_lines: "{{ __pve_lxc_raw_config_lines[(__pve_lxc_raw_config_main_section_end | int) :] }}"
|
||||
|
||||
- name: Determine whether raw LXC config lines need reconciling
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_raw_config_existing: "{{ __pve_lxc_raw_config_main_lines | select('match', __pve_lxc_raw_config_prefix_pattern) | list }}"
|
||||
__pve_lxc_raw_config_legacy_markers: "{{ __pve_lxc_raw_config_main_lines | select('match', __pve_lxc_raw_config_legacy_marker_pattern) | list }}"
|
||||
__pve_lxc_raw_config_preserved_lines: >-
|
||||
{{
|
||||
__pve_lxc_raw_config_main_lines
|
||||
| reject('match', __pve_lxc_raw_config_prefix_pattern)
|
||||
| reject('match', __pve_lxc_raw_config_legacy_marker_pattern)
|
||||
| list
|
||||
}}
|
||||
|
||||
# Order-sensitive on purpose: LXC evaluates these lines in order, so a reorder is a change.
|
||||
- name: Set raw LXC config dirty flag
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_raw_config_dirty: "{{ __pve_lxc_raw_config_existing != __pve_lxc_raw_config_desired }}"
|
||||
|
||||
- name: Set raw LXC config file rewrite flag
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_raw_config_needs_rewrite: "{{ __pve_lxc_raw_config_dirty or (__pve_lxc_raw_config_legacy_markers | length > 0) }}"
|
||||
|
||||
# One copy (temporary file and rename), so an interrupted run leaves the old or the new content,
|
||||
# never a file without its lxc.* lines. Mode omitted: the file exists already and copy keeps its
|
||||
# mode, which Proxmox owns. No backup: pmxcfs is small and replicated to every node.
|
||||
- name: Reconcile raw LXC config file atomically (namespace-exclusive sync) # noqa: risky-file-permissions
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
dest: "/etc/pve/lxc/{{ pve_lxc_vmid }}.conf"
|
||||
# Double-quoted: in a folded scalar Jinja would receive a literal backslash-n, not a newline.
|
||||
content: "{{ (__pve_lxc_raw_config_preserved_lines + __pve_lxc_raw_config_desired + __pve_lxc_raw_config_snapshot_lines) | join('\n') + '\n' }}"
|
||||
when:
|
||||
- __pve_lxc_raw_config_needs_rewrite
|
||||
|
||||
# Ansible backup copies (<vmid>.conf.<pid>.<timestamp>~) must not pile up on pmxcfs.
|
||||
- name: Find stale raw LXC config backups
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.find:
|
||||
paths: /etc/pve/lxc
|
||||
patterns: "{{ pve_lxc_vmid }}.conf.*~"
|
||||
register: __pve_lxc_raw_config_backups
|
||||
|
||||
- name: Remove stale raw LXC config backups
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "{{ __pve_lxc_backup.path }}"
|
||||
state: absent
|
||||
loop: "{{ __pve_lxc_raw_config_backups.files }}"
|
||||
loop_control:
|
||||
loop_var: __pve_lxc_backup
|
||||
label: "{{ __pve_lxc_backup.path }}"
|
||||
|
||||
# Skipped for a stopped container, so a config change never starts it; the new lines take
|
||||
# effect on its next start.
|
||||
- name: Restart LXC if raw config changed
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
state: restarted
|
||||
timeout: 300
|
||||
when:
|
||||
- __pve_lxc_raw_config_dirty
|
||||
- not ansible_check_mode
|
||||
- pve_lxc_state != "stopped"
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Ensure LXC state
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
state: "{{ pve_lxc_state }}"
|
||||
@@ -0,0 +1,113 @@
|
||||
---
|
||||
- name: Update LXC config (no restart)
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
# Sent explicitly: community.proxmox 2.0.0 forwarded its argspec default "default" on
|
||||
# update, which Proxmox rejects (2.1.0 drops it).
|
||||
cmode: "{{ pve_lxc_cmode | default('tty') }}"
|
||||
memory: "{{ pve_lxc_memory }}"
|
||||
cores: "{{ pve_lxc_cores | default(omit) }}"
|
||||
swap: "{{ pve_lxc_swap | default(omit) }}"
|
||||
nameserver: "{{ pve_lxc_nameserver | default(omit) }}"
|
||||
netif:
|
||||
net0: >-
|
||||
{{ (['name=' ~ pve_lxc_net_interface, 'bridge=' ~ pve_lxc_net.bridge,
|
||||
'ip=' ~ ansible_host ~ '/' ~ pve_lxc_net_prefix, 'gw=' ~ pve_lxc_net.gw,
|
||||
'tag=' ~ pve_lxc_net.tag] + (['firewall=1'] if pve_lxc_firewall | bool else []))
|
||||
| join(',') }}
|
||||
pubkey: "{{ pve_lxc_pubkey }}"
|
||||
features: "{{ pve_lxc_features if (pve_lxc_features | length > 0) else omit }}"
|
||||
onboot: "{{ __pve_lxc_effective_onboot }}"
|
||||
state: present
|
||||
update: true
|
||||
register: __pve_lxc_config_update
|
||||
|
||||
- name: Restart LXC if config changed and restart-on-change is enabled
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
# Proxmox only applies some config (e.g. `features`) on next container
|
||||
# start, not live via pct set.
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
state: restarted
|
||||
timeout: 300
|
||||
when:
|
||||
- __pve_lxc_config_update.changed | default(false)
|
||||
- pve_lxc_restart_on_config_change
|
||||
- not ansible_check_mode
|
||||
|
||||
- name: Resize disk if desired size is larger
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
disk: "{{ pve_lxc_disk }}"
|
||||
state: present
|
||||
update: true
|
||||
when:
|
||||
- pve_lxc_manage_disk
|
||||
- __pve_lxc_resize_disk
|
||||
- not ansible_check_mode
|
||||
register: __pve_lxc_disk_resize
|
||||
|
||||
- name: Set disk resize API flag
|
||||
ansible.builtin.set_fact:
|
||||
__pve_lxc_disk_resized: >-
|
||||
{{
|
||||
(__pve_lxc_disk_resized | default(false))
|
||||
or (__pve_lxc_disk_resize.changed | default(false))
|
||||
}}
|
||||
|
||||
- name: Fail if disk resize was requested but not applied
|
||||
ansible.builtin.fail:
|
||||
msg: "Disk resize requested but Proxmox did not apply it"
|
||||
when:
|
||||
- pve_lxc_manage_disk
|
||||
- __pve_lxc_resize_disk
|
||||
- not __pve_lxc_disk_resized
|
||||
- not ansible_check_mode
|
||||
|
||||
# Resize the filesystem inside the container using pct resize
|
||||
- name: Resize filesystem inside container
|
||||
delegate_to: "{{ pve_lxc_node }}"
|
||||
become: true
|
||||
ansible.builtin.command: >
|
||||
pct resize {{ pve_lxc_vmid }} rootfs {{ __pve_lxc_desired_disk_size }}G
|
||||
when:
|
||||
- pve_lxc_manage_disk
|
||||
- __pve_lxc_resize_disk
|
||||
- __pve_lxc_disk_resized | default(false)
|
||||
- not ansible_check_mode
|
||||
register: __pve_lxc_pct_resize_result
|
||||
changed_when: >
|
||||
__pve_lxc_pct_resize_result.rc == 0 and
|
||||
(
|
||||
'successfully resized' in __pve_lxc_pct_resize_result.stdout | lower or
|
||||
'size of logical volume' in __pve_lxc_pct_resize_result.stdout | lower
|
||||
)
|
||||
failed_when: >
|
||||
__pve_lxc_pct_resize_result.rc != 0 and
|
||||
'no resize needed' not in (__pve_lxc_pct_resize_result.stderr | lower)
|
||||
|
||||
- name: Restart LXC if disk was resized
|
||||
no_log: true # defence in depth: the module already masks the API token secret
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ pve_lxc_vmid }}"
|
||||
node: "{{ pve_lxc_node }}"
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
state: restarted
|
||||
timeout: 300
|
||||
when:
|
||||
- __pve_lxc_pct_resize_result is defined
|
||||
- __pve_lxc_pct_resize_result.changed
|
||||
- not ansible_check_mode
|
||||
- pve_lxc_reboot_if_required | bool
|
||||
@@ -0,0 +1,88 @@
|
||||
---
|
||||
# The input rules the argument spec cannot express. main.yml imports this file under
|
||||
# tags: always, before any change; each assert keeps the condition under which its input is read.
|
||||
|
||||
- name: Assert the Proxmox API credentials are set
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pve_lxc_api_user | length > 0
|
||||
- pve_lxc_api_token_secret is defined and pve_lxc_api_token_secret | length > 0
|
||||
fail_msg: >-
|
||||
The Proxmox API calls need pve_lxc_api_user (bare user name, the role appends
|
||||
@<pve_lxc_api_realm>) and pve_lxc_api_token_secret (normally vaulted). Neither has a usable
|
||||
default: set them in the inventory, or set pve_lxc_manage_lifecycle to false for a container
|
||||
whose node Ansible does not manage.
|
||||
quiet: true
|
||||
when: pve_lxc_manage_lifecycle | bool
|
||||
|
||||
- name: Assert the network prefix length is set
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pve_lxc_net_prefix | string is match('^([1-9]|[12][0-9]|3[0-2])$')
|
||||
fail_msg: >-
|
||||
pve_lxc_net_prefix must be the subnet prefix length of the container network (1 to 32),
|
||||
for example 24. It has no role default because it is environment-specific: set it in the
|
||||
inventory.
|
||||
quiet: true
|
||||
when:
|
||||
- pve_lxc_manage_lifecycle | bool
|
||||
- pve_lxc_state != "absent"
|
||||
|
||||
# Reads only the variable, so a malformed list also fails under --check on a container that does
|
||||
# not exist yet. A bare string would be checked character by character, with a meaningless message.
|
||||
- name: Fail if pve_lxc_raw_config is set but not a list
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
pve_lxc_raw_config must be a YAML list of strings (one raw config line per
|
||||
item), not a bare string or mapping -- a plain string is iterated
|
||||
character-by-character by the checks below, which produces a
|
||||
nonsensical error. Got type: {{ pve_lxc_raw_config | type_debug }}.
|
||||
when:
|
||||
- pve_lxc_manage_lifecycle | bool
|
||||
- pve_lxc_state != "absent"
|
||||
- pve_lxc_raw_config is defined
|
||||
- pve_lxc_raw_config is truthy
|
||||
- (pve_lxc_raw_config is string) or (pve_lxc_raw_config is not sequence)
|
||||
|
||||
- name: Determine malformed pve_lxc_raw_config entries
|
||||
ansible.builtin.set_fact:
|
||||
# default(..., true) also turns an explicit null or "" into [], which the reconcile's list
|
||||
# concatenation needs. The pattern is anchored at both ends: an item holding two lines would be
|
||||
# written as two and never match the desired list on read-back, restarting the container on
|
||||
# every run.
|
||||
__pve_lxc_raw_config_malformed: "{{ pve_lxc_raw_config | default([], true) | reject('match', __pve_lxc_raw_config_prefix_pattern) | list }}"
|
||||
when:
|
||||
- pve_lxc_manage_lifecycle | bool
|
||||
- pve_lxc_state != "absent"
|
||||
|
||||
- name: Fail on malformed pve_lxc_raw_config entries
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
pve_lxc_raw_config entries must be a single line starting with the literal
|
||||
prefix "lxc." (no leading whitespace, comments, other directives, or
|
||||
embedded newlines) so the namespace-exclusive sync below can safely
|
||||
treat "^lxc\." as its ownership boundary. Offending entries:
|
||||
{{ __pve_lxc_raw_config_malformed }}
|
||||
when:
|
||||
- pve_lxc_manage_lifecycle | bool
|
||||
- pve_lxc_state != "absent"
|
||||
- __pve_lxc_raw_config_malformed | length > 0
|
||||
|
||||
# Proxmox skips a rule line it cannot parse, so a malformed DROP would silently open what it was
|
||||
# meant to close. Only the shape is checked; `pve-firewall compile` on the node proves the syntax.
|
||||
- name: Validate guest firewall inputs
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pve_lxc_firewall_policy_in in ['ACCEPT', 'DROP', 'REJECT']
|
||||
- pve_lxc_firewall_policy_out in ['ACCEPT', 'DROP', 'REJECT']
|
||||
- pve_lxc_firewall_rules is sequence
|
||||
- pve_lxc_firewall_rules is not string
|
||||
- pve_lxc_firewall_rules | reject('match', '^(IN|OUT) (ACCEPT|DROP|REJECT)( [^\n]*)?$') | list | length == 0
|
||||
fail_msg: >-
|
||||
pve_lxc_firewall_policy_in/_out must be ACCEPT, DROP or REJECT and pve_lxc_firewall_rules a list of
|
||||
single-line Proxmox rules starting with "IN|OUT ACCEPT|DROP|REJECT".
|
||||
quiet: true
|
||||
when:
|
||||
- pve_lxc_manage_lifecycle | bool
|
||||
- pve_lxc_state != "absent"
|
||||
- pve_lxc_firewall | bool
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Wait for SSH to become available
|
||||
delegate_to: localhost
|
||||
ansible.builtin.wait_for:
|
||||
host: "{{ ansible_host }}"
|
||||
port: 22
|
||||
timeout: 3600
|
||||
@@ -0,0 +1,11 @@
|
||||
[OPTIONS]
|
||||
enable: 1
|
||||
ipfilter: 1
|
||||
macfilter: 1
|
||||
policy_in: {{ pve_lxc_firewall_policy_in }}
|
||||
policy_out: {{ pve_lxc_firewall_policy_out }}
|
||||
|
||||
[RULES]
|
||||
{% for __pve_lxc_firewall_rule in pve_lxc_firewall_rules %}
|
||||
{{ __pve_lxc_firewall_rule }}
|
||||
{% endfor %}
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# The onboot flag sent to Proxmox on create and update. Derived from the desired state, not an
|
||||
# input: a container meant to be stopped must not start when its node reboots, so stopped forces
|
||||
# false even when pve_lxc_onboot is true. absent never reaches the create or update task.
|
||||
__pve_lxc_effective_onboot: "{{ (pve_lxc_onboot | bool) and pve_lxc_state != 'stopped' }}"
|
||||
# Authorization header of the ansible.builtin.uri calls, derived from the pve_lxc_api_* inputs.
|
||||
__pve_lxc_api_auth_header: "PVEAPIToken={{ pve_lxc_api_user }}@{{ pve_lxc_api_realm }}!{{ pve_lxc_api_token_id }}={{ pve_lxc_api_token_secret }}"
|
||||
# Raw config line patterns, read by validate.yml and raw_config.yml.
|
||||
__pve_lxc_raw_config_prefix_pattern: '^lxc\.[^\n]*$'
|
||||
__pve_lxc_raw_config_legacy_marker_pattern: '^# (BEGIN|END) ANSIBLE MANAGED BLOCK \(lxc_raw_config\)$'
|
||||
__pve_lxc_raw_config_section_header_pattern: '^\[.*\]$'
|
||||
@@ -52,6 +52,7 @@ templating error instead of the role's own message.
|
||||
| `system_baseline_reboot_throttle` | `0` | no | Hosts that reboot at the same time; `0` is no limit, `1` one at a time (see "Rebooting one host at a time") |
|
||||
| `system_baseline_reboot_post_delay` | `0` | no | Seconds to wait after a rebooted host answers again |
|
||||
| `system_baseline_apt_daily_timeout` | empty | no | Systemd time span written as `TimeoutStartSec` of `apt-daily.service`; empty leaves the host alone (see "Bounding a hung apt-daily.service") |
|
||||
| `system_baseline_apt_tmpdir` | `/var/cache/system-baseline-apt-tmp` | no | Directory the apt upgrade uses as `TMPDIR`; absolute, never `/tmp` or `/var/tmp` (see "Apt scratch directory") |
|
||||
| `system_baseline_update` | `true` | no | Run the package update in the main flow; `false` skips it (the `update` entry point ignores it) |
|
||||
|
||||
A flat `system_baseline_*` input replaces that value entirely. To change one key of a profile dict, use `system_baseline_profile_overrides`, for example to let unattended-upgrades reboot a group on its own:
|
||||
@@ -93,7 +94,7 @@ The two task files besides `main` are a supported interface, for a caller that d
|
||||
|
||||
### `update`
|
||||
|
||||
`tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else. It does not read `system_baseline_update`: calling the entry point is the request to update. In check mode it previews the upgrade; the main flow does not (see "Check mode").
|
||||
`tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else. It does not read `system_baseline_update`: calling the entry point is the request to update. In check mode it previews the upgrade; the main flow does not (see "Check mode"). It reads `system_baseline_apt_tmpdir` (see "Apt scratch directory").
|
||||
|
||||
### `reboot`
|
||||
|
||||
@@ -129,6 +130,7 @@ The scenario `molecule/default/` runs in CI only, on one platform: `${MOLECULE_I
|
||||
- Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, asserting the resolved inputs.
|
||||
- Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout.
|
||||
- Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off.
|
||||
- Converge also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. Verify reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there.
|
||||
- Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot.
|
||||
- The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list.
|
||||
|
||||
@@ -193,6 +195,14 @@ The profile key `apt_upgrade` (`safe` or `dist`, resolved to `system_baseline_ap
|
||||
- The `update` entry point follows the same input: it upgrades with `dist` when `system_baseline_system_type` is `pve`. Without a `system_baseline_system_type` (the entry point does not require one) it stays on `safe`.
|
||||
- Only the apt upgrade changes. Autoremove and autoclean, the check-mode skip and unattended-upgrades are as before; the example blacklist below keeps unattended-upgrades away from the Proxmox packages.
|
||||
|
||||
### Apt scratch directory
|
||||
|
||||
The upgrade runs over the SSH connection Ansible uses. An `openssh-server` upgrade restarts `ssh.service`, and a unit with `PrivateTmp=yes` (the `systemd_hardening` role sets it) has its own `/tmp` and `/var/tmp`, which systemd deletes when the unit stops. The files apt staged there for the running upgrade then disappear and dpkg fails, leaving packages unpacked but not configured. So the `update` flow creates `system_baseline_apt_tmpdir` (root, mode `0700`), runs the upgrade and the autoremove with `TMPDIR` set to it, and opens a new connection afterwards, so that later tasks get a fresh private `/tmp`.
|
||||
|
||||
- The value must be an absolute path of letters, digits, `.`, `_`, `-` and `/`, without `..`, and not `/tmp`, `/var/tmp` or a path below them; anything else stops the run before a change.
|
||||
- The directory is also created in check mode (the autoremove runs there with the same `TMPDIR`), so a dry run reports it once, on a host that does not have it yet.
|
||||
- Changing the value does not remove the old directory.
|
||||
|
||||
### Check mode
|
||||
|
||||
In a dry run (`--check`) the main flow does not run the apt upgrade: a package that is only waiting for the next patch run, or a package cache older than an hour, is not drift, and the package module reports both as `changed`, so a scheduled dry run would flag every host whenever a package landed in between. The autoremove and autoclean step still runs, and is checked: a leftover package it would remove is reported as `changed`, on purpose. `apt-get autoclean` runs in this step in a real run, in the main flow and in the `update` entry point. The `update` entry point is unchanged: it is an explicit request to update, so in check mode it still previews the upgrade.
|
||||
|
||||
@@ -11,6 +11,10 @@ system_baseline_reboot_throttle: 0
|
||||
system_baseline_reboot_post_delay: 0
|
||||
# Systemd time span (for example 1h) written as TimeoutStartSec of apt-daily.service; empty leaves the host alone (tasks/apt_daily_timeout.yml).
|
||||
system_baseline_apt_daily_timeout: ""
|
||||
# Directory the apt upgrade and autoremove use as TMPDIR (tasks/update.yml): absolute, never /tmp or /var/tmp. An openssh-server upgrade
|
||||
# restarts ssh.service, and with PrivateTmp=yes systemd then deletes that unit's /tmp and /var/tmp while the upgrade still needs its staged files.
|
||||
# Created root-owned, mode 0700.
|
||||
system_baseline_apt_tmpdir: /var/cache/system-baseline-apt-tmp
|
||||
# Run the package update (tasks/update.yml) in the main flow. false skips it, for hosts that are patched by a separate,
|
||||
# operator-run flow; the tasks_from: update entry point does not read it.
|
||||
system_baseline_update: true
|
||||
|
||||
@@ -129,6 +129,16 @@ argument_specs:
|
||||
C(/etc/systemd/system/apt-daily.service.d/10-timeout.conf), so a hung apt run is stopped. Empty leaves the host alone; clearing
|
||||
the value later does not remove a file already written. A value of C(0) means no timeout to systemd.
|
||||
C(apt-daily-upgrade.service) is not changed. Tag C(apt-daily-timeout).
|
||||
system_baseline_apt_tmpdir:
|
||||
type: str
|
||||
default: /var/cache/system-baseline-apt-tmp
|
||||
description:
|
||||
- >-
|
||||
Directory the apt upgrade and autoremove use as C(TMPDIR). It must be an absolute path made of letters, digits, C(.), C(_), C(-)
|
||||
and C(/), without C(..), and not C(/tmp) or C(/var/tmp) or anything below them: an C(openssh-server) upgrade restarts
|
||||
C(ssh.service), and when that unit has C(PrivateTmp=yes) systemd deletes its C(/tmp) and C(/var/tmp) while the upgrade still
|
||||
needs the files apt staged there. The role creates it, owned by root with mode C(0700). An invalid value stops the run before
|
||||
any change. Changing the value later does not remove the old directory.
|
||||
system_baseline_unattended_upgrade_package_blacklist:
|
||||
type: list
|
||||
elements: str
|
||||
@@ -162,6 +172,10 @@ argument_specs:
|
||||
- >-
|
||||
A supported entry point (C(tasks_from=update)) for a caller that drives its own reboot, for example a
|
||||
Kubernetes node patch flow that drains the node first.
|
||||
- >-
|
||||
It creates C(system_baseline_apt_tmpdir), runs the upgrade and the autoremove with C(TMPDIR) set to it, and then opens a new
|
||||
connection, so that a restart of C(ssh.service) during the upgrade does not remove the files apt needs. It reads that input
|
||||
although the entry point has no argument specification of its own.
|
||||
reboot:
|
||||
short_description: Compute system_baseline_reboot_required and reboot when allowed
|
||||
description:
|
||||
|
||||
@@ -64,6 +64,23 @@
|
||||
that: "'system_baseline_apt_upgrade is' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
# The apt scratch directory becomes TMPDIR of the upgrade: a path under /tmp or /var/tmp (which a restart of ssh.service can delete), a relative
|
||||
# path and a `..` each stop the run before any change, in the main flow and in the update entry point (which does not run validate.yml).
|
||||
- name: A bad apt scratch directory is refused
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse each bad value
|
||||
ansible.builtin.include_tasks: tasks/refuse_apt_tmpdir_entries.yml
|
||||
vars:
|
||||
system_baseline_refused_tmpdir: "{{ item }}"
|
||||
loop:
|
||||
- /tmp
|
||||
- /var/tmp/apt
|
||||
- /var/cache/../../tmp/x
|
||||
- var/cache/apt-tmp
|
||||
- ""
|
||||
|
||||
# The reboot inputs are whole numbers, 0 or more: a negative number and a boolean each stop the run before a host reboots,
|
||||
# in the main flow and in the reboot entry point (which does not run validate.yml).
|
||||
- name: A bad reboot throttle or post-reboot delay is refused
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
# One refusal per entry point: the main flow and the update entry point must both stop on validation, with a message that names the variable.
|
||||
- name: Run the role with a bad apt scratch directory
|
||||
block:
|
||||
- name: Include system_baseline
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: "{{ system_baseline_refused_entry }}"
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_apt_tmpdir: "{{ system_baseline_refused_tmpdir }}"
|
||||
- name: Unreachable when validation works
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ran with an invalid system_baseline_apt_tmpdir
|
||||
rescue:
|
||||
- name: The validation stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'system_baseline_apt_tmpdir must be' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Refuse the value in the main flow and in the update entry point
|
||||
ansible.builtin.include_tasks: refuse_apt_tmpdir.yml
|
||||
vars:
|
||||
system_baseline_refused_entry: "{{ entry }}"
|
||||
loop:
|
||||
- main
|
||||
- update
|
||||
loop_control:
|
||||
loop_var: entry
|
||||
@@ -101,6 +101,26 @@
|
||||
- system_baseline_verify_apt_daily_show.stdout_lines is contains('TimeoutStartUSec=1h')
|
||||
quiet: true
|
||||
|
||||
# The scenario skips the `update` tag (molecule.yml), so the upgrade never runs here and its scratch directory is never created. This reads the
|
||||
# task file on the controller and checks that the directory is private and that both apt tasks use it as TMPDIR.
|
||||
- name: The update tasks give the apt upgrade a private scratch directory
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Read the update tasks
|
||||
ansible.builtin.set_fact:
|
||||
system_baseline_verify_update_tasks: "{{ lookup('ansible.builtin.file', playbook_dir ~ '/../../tasks/update.yml') }}"
|
||||
|
||||
- name: The scratch directory is created private and both apt tasks use it
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ path:\s"\{\{ system_baseline_apt_tmpdir \}\}"$')
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ mode:\s"0700"$')
|
||||
- system_baseline_verify_update_tasks | regex_findall('(?m)^ TMPDIR:\s"\{\{ system_baseline_apt_tmpdir \}\}"$') | length == 2
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ ansible.builtin.meta:\sreset_connection$')
|
||||
quiet: true
|
||||
|
||||
# The reboot entry point is a supported interface: with system_baseline_reboot_if_required
|
||||
# false it only sets system_baseline_reboot_required. Here and not in converge, because it
|
||||
# creates and removes the marker file, which the idempotence run would report as a change.
|
||||
|
||||
@@ -6,6 +6,21 @@
|
||||
- name: Validate the apt upgrade mode
|
||||
ansible.builtin.import_tasks: validate_apt_upgrade.yml
|
||||
|
||||
- name: Validate the apt scratch directory
|
||||
ansible.builtin.import_tasks: validate_apt_tmpdir.yml
|
||||
|
||||
# apt and the package module put their temporary files, including the staged .deb files, in TMPDIR. A restart of ssh.service during the upgrade
|
||||
# (an openssh-server update) deletes a PrivateTmp /tmp, so TMPDIR points at a directory systemd leaves alone. Created in check mode too,
|
||||
# because the autoremove below runs there with the same TMPDIR.
|
||||
- name: Create the apt scratch directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ system_baseline_apt_tmpdir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0700"
|
||||
become: true
|
||||
|
||||
# safe is the apt module's name for the plain upgrade (apt-get upgrade --with-new-pkgs), what `true` meant here before; dist runs
|
||||
# apt-get dist-upgrade (profile key apt_upgrade, `pve` by default).
|
||||
- name: Update & upgrade apt packages
|
||||
@@ -13,6 +28,8 @@
|
||||
update_cache: true
|
||||
upgrade: "{{ system_baseline_apt_upgrade }}"
|
||||
cache_valid_time: 3600
|
||||
environment:
|
||||
TMPDIR: "{{ system_baseline_apt_tmpdir }}"
|
||||
become: true
|
||||
when: not (ansible_check_mode and __system_baseline_main_flow | default(false))
|
||||
|
||||
@@ -21,4 +38,12 @@
|
||||
ansible.builtin.package:
|
||||
autoremove: true
|
||||
autoclean: true
|
||||
environment:
|
||||
TMPDIR: "{{ system_baseline_apt_tmpdir }}"
|
||||
become: true
|
||||
|
||||
# A restart of ssh.service ends the connection that was open during the upgrade; a new one gets a new private /tmp, which later tasks
|
||||
# of the play (and a caller's own tasks) may use.
|
||||
- name: Open a new connection after the upgrade
|
||||
ansible.builtin.meta: reset_connection
|
||||
when: not (ansible_check_mode and __system_baseline_main_flow | default(false))
|
||||
@@ -39,6 +39,10 @@
|
||||
ansible.builtin.import_tasks: validate_apt_upgrade.yml
|
||||
tags: always
|
||||
|
||||
- name: Validate the apt scratch directory
|
||||
ansible.builtin.import_tasks: validate_apt_tmpdir.yml
|
||||
tags: always
|
||||
|
||||
- name: Validate the reboot inputs
|
||||
ansible.builtin.import_tasks: validate_reboot.yml
|
||||
tags: always
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
# Shared by validate.yml and update.yml: the tasks_from: update entry point does not run validate.yml. The directory becomes TMPDIR of the apt
|
||||
# upgrade, so it must not be one that an ssh.service restart (PrivateTmp=yes) deletes, and it is created as root: a relative path, a `..` or an
|
||||
# odd character must stop the run before anything changes.
|
||||
- name: Validate the apt scratch directory
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_apt_tmpdir is string
|
||||
- system_baseline_apt_tmpdir is match('^/[A-Za-z0-9._/-]+\Z')
|
||||
- "'..' not in system_baseline_apt_tmpdir"
|
||||
- system_baseline_apt_tmpdir is not match('^/(var/)?tmp(/|\Z)')
|
||||
fail_msg: >-
|
||||
system_baseline_apt_tmpdir must be an absolute path of letters, digits, . _ - and /, without .., and not /tmp, /var/tmp or a path below them.
|
||||
quiet: true
|
||||
tags: always
|
||||
@@ -1,4 +1,5 @@
|
||||
COPYING no-smart-quotes
|
||||
LICENSES/EUPL-1.2.txt no-smart-quotes
|
||||
LICENSES/GPL-3.0-only.txt no-smart-quotes
|
||||
LICENSES/GPL-3.0-or-later.txt no-smart-quotes
|
||||
roles/docker/molecule/default/files/build-stub-repo.sh shebang # run by the docker scenario, not by Ansible
|
||||
|
||||
Reference in new issue
Block a user