Skip to content

feat(infra): onboard an Ansible infra repo - #5149

Merged
dan-petty merged 3 commits into
mainfrom
feat/5121-infra-onboard
Nov 12, 2026
Merged

dan-petty merged 3 commits into
mainfrom
feat/5121-infra-onboard

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Every later devops infra command needs to know the infra repos, their checkouts, their Ansible layout and what an agent may do on their hosts. devops infra onboard checks a repo from local files and local tool output only, prints one row for each of 17 checks, and with --confirm writes its entry of infra.repos. The entry holds operational keys only; the facts of the repo come from its project profile (.devops/project.toml, the ansible-k8s template and detection), the first loader of #4627. An agent cannot set an access level above none. ansible-core and ansible-runner are pinned in one tool environment, and only ansible-runner goes on PATH.

To set homelab to full, a person runs: uv run devops infra onboard dan-petty/homelab --agent-access full --confirm

Closes #5121

Change: openspec/changes/archive/2026-11-12-5121-onboard-an-ansible-infra-repo/

Add the command group `devops infra` with `devops infra onboard <repo>`.
The command reads only the local checkout and local tool output, and
prints one row for each of 17 checks with a state, a reason and a step.
With --confirm, it writes the entry of the repo in infra.repos. An agent
caller cannot give an agent access level above none. --dry-run starts no
process and writes nothing.

Add the first project profile loader (#4627): the field defaults, the
type template templates/profiles/ansible-k8s.toml, detection and the
.devops/project.toml of the repo merge in that order, and each value
records its source. The facts of an infra repo live in its profile. The
infra.repos entry holds operational keys only.

Pin ansible-core 2.22.0 and ansible-runner 2.4.3 in one environment,
[python.ansible-core] of the tools lock, and install it in the
devcontainer image. Only ansible-runner goes on PATH.

Move the caller detection from telemetry/usage_errors.py to
core/caller.py, so the usage-error record and the access level read one
source.
@dan-petty dan-petty added type/feature Type feature: a new function scope/infra Docker container images, DevContainers, and infrastructure tooling labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Live validation on dan-petty/homelab

Run on 2026-11-12 from an empty config file (DEVOPS_CLI_CONFIG=<scratch>/empty-config.yaml, 0 bytes, no global config). The checkout is an export of homelab origin/main at f5961bd (git archive; the live checkout on its feature branch was not switched). No command reached a host or the cluster. Host names are shortened; the report prints no address.

1. uv run devops infra onboard dan-petty/homelab --path <scratch>/homelab-main (exit 1)

# Onboarding of dan-petty/homelab at <scratch>/homelab-main
1. The Ansible tool environment is installed: present (ansible-core 2.22.0)
2. The project profile of the repository has the type ansible-k8s: listed (detected: ansible.cfg; the repository has no .devops/project.toml. These values differ from the type template.)
   - extends = "ansible-k8s" (detected: ansible.cfg)
   - ansible.inventory = ["ansible/inventory/hosts.yaml"] (detected: ansible.cfg)
   - ansible.playbook_dir = "ansible/playbooks" (detected: ansible/playbooks)
   - ansible.roles_path = ["ansible/roles"] (detected: ansible.cfg)
   - kubernetes.dir = "k8s" (detected: k8s)
   Step: Commit .devops/project.toml with these values, so that the profile does not change when a file that detection reads changes.
3. ansible.cfg is at the root of the repository: present
4. The inventory names hosts: present (6 hosts in 6 groups)
   - debian_nodes: 4 hosts
   - gpu_nodes: 4 hosts
   - k3s_agent: 3 hosts
   - k3s_cluster: 4 hosts
   - k3s_server: 1 host
   - offline: 2 hosts
5. The inventory has the group offline for hosts out of service: present (2 hosts out of service)
   - bombas
   - workhorse
6. The repository holds playbooks: present (17 playbooks in ansible/playbooks)
   - ansible/playbooks/00_bootstrap_user.yaml
   - ansible/playbooks/01_bootstrap.yaml
   - ansible/playbooks/02_nvidia.yaml
   - ansible/playbooks/03_k3s.yaml
   - ansible/playbooks/04_gpu_validation.yaml
   - ansible/playbooks/05_cluster_maintenance.yaml
   - ansible/playbooks/06_cluster_backup.yaml
   - ansible/playbooks/07_cluster_upgrade.yaml
   - ansible/playbooks/08_mount_nvme.yaml
   - ansible/playbooks/09_system_update.yaml
   - ansible/playbooks/10_rolling_restart.yaml
   - ansible/playbooks/11_secrets_encryption.yaml
   - ansible/playbooks/12_move_ollama_models.yaml
   - ansible/playbooks/13_crash_capture.yaml
   - ansible/playbooks/configure_registries.yaml
   - ansible/playbooks/health_check.yaml
   - ansible/playbooks/site.yaml
7. The repository holds roles: present (5 roles)
   - common
   - k3s_agent
   - k3s_server
   - k8s_gpu
   - nvidia
8. collections/requirements.yml pins each collection: missing (collections/requirements.yml is not in the repository. The plays use ansible.posix, community.general, kubernetes.core.)
   Step: Add collections/requirements.yml, with an exact version for each collection that the plays use.
9. Host key checks are on: present
10. ~/.ssh/known_hosts holds the key of each host in service: present (4 hosts in service)
11. A devops ssh key of the prefix ansible exists: present
   - ansible-id_ed25519-20260909
12. The kube context of the repository is in the kubeconfig: missing (No kube context is set. The kubeconfig holds these contexts.)
   - homelab-k3s
   - homelab-k3s-tunnel
   Step: Give the context with --kube-context <name>.
13. A CI workflow checks the repository: missing
   Step: Add a CI workflow that runs ansible-lint and ansible-playbook --syntax-check on each playbook.
14. Each host in service names its node service (devops_infra_node_service): listed (4 hosts in service do not set devops_infra_node_service.)
   - condor
   - gemini
   - hawk
   - hog
   Step: Set devops_infra_node_service, such as k3s-agent, on each host that runs a Kubernetes node.
15. No task runs for real in check mode (check_mode: false): listed (14 tasks run for real when a plan runs the playbook in check mode.)
   - ansible/playbooks/11_secrets_encryption.yaml:40 Read secrets encryption status
   - ansible/playbooks/11_secrets_encryption.yaml:54 Count Secrets still stored as plaintext
   - ansible/playbooks/12_move_ollama_models.yaml:84 Check if the model store is already a mount point
   - ansible/playbooks/12_move_ollama_models.yaml:155 Measure the source of the copy
   - ansible/playbooks/12_move_ollama_models.yaml:163 Measure the target folder
   - ansible/playbooks/12_move_ollama_models.yaml:212 Copy the store, first pass (the pods keep running)
   - ansible/playbooks/12_move_ollama_models.yaml:225 Copy the store, last pass (--delete)
   - ansible/playbooks/12_move_ollama_models.yaml:284 Check if a pod still uses the old store
   - ansible/playbooks/tasks/k3s_node_reboot.yaml:3 Read Kubernetes node readiness and scheduling state
   - ansible/playbooks/tasks/k3s_node_reboot.yaml:31 Wait for K3s service to become active
   - ansible/playbooks/tasks/k3s_node_reboot.yaml:41 Wait for node to report Ready in Kubernetes
   - ansible/playbooks/tasks/k3s_node_reboot.yaml:54 Verify NVIDIA driver and GPUs after reboot
   - ansible/playbooks/tasks/k3s_node_reboot.yaml:67 Read running kernel
   - ansible/roles/k3s_server/tasks/main.yaml:30 Wait for K3s node to report Ready
   Step: Make sure that each of these tasks only reads.
16. No Makefile target drains, restarts or reboots a node: listed (16 targets change a node outside devops.)
   - drain-agent
   - uncordon-agent
   - restart-agent
   - drain-condor
   - uncordon-condor
   - restart-condor
   - drain-hawk
   - uncordon-hawk
   - restart-hawk
   - drain-bombas
   - uncordon-bombas
   - restart-bombas
   - drain-gemini
   - uncordon-gemini
   - restart-gemini
   - rolling-restart
   Step: devops owns the node life cycle: cordon, drain, restart and reboot. Move these steps out of the Makefile.
17. The repository is in infra.repos: missing
   Step: Run the command again with --confirm to write the entry, at agent access none unless a person gives --agent-access.

2. The same with --confirm (exit 1: rows 8, 12 and 13 are missing)

The report is the same, except row 17:

17. The repository is in infra.repos: present (agent access none; written to <scratch>/empty-config.yaml)

The config file after the run:

infra:
  repos:
  - repo: dan-petty/homelab
    path: <scratch>/homelab-main
    kube_context: null
    ssh_key_prefix: ansible
    agent_access: none

3. The commit before homelab#24 (e022912): host key checks

Row 9 of the same report on e022912 finds the settings that homelab#24 removed, the inventory variable too:

9. Host key checks are on: missing (4 settings turn host key checks off.)
   - ansible.cfg: host_key_checking = False
   - ansible.cfg: ssh_args StrictHostKeyChecking=no
   - ansible.cfg: ssh_args UserKnownHostsFile=/dev/null
   - inventory: ansible_ssh_common_args StrictHostKeyChecking=no (6 hosts)
   Step: Remove these settings, and keep the key of each host in ~/.ssh/known_hosts. An agent apply needs host key checks on.

4. An agent raises the level (exit 1, the config file keeps every byte)

✗ An agent cannot set the agent access level of an infra repo to full. Only a person sets a level above none, in the setting infra.repos[].agent_access. Run the command again with no --agent-access, or ask a person to run it.

5. --confirm --dry-run (exit 0, no process, no write)

Plan for the onboarding of dan-petty/homelab at <scratch>/homelab-main
  1. EXEC the Ansible config of <scratch>/homelab-main
       ~/.local/share/devops-cli/tools/ansible-core/2.22.0/bin/ansible-config dump --format json --only-changed  [only if an Ansible tool environment is installed]
  2. EXEC the Ansible inventory of <scratch>/homelab-main
       ~/.local/share/devops-cli/tools/ansible-core/2.22.0/bin/ansible-inventory -i '<inventory>' --list  [only if an Ansible tool environment is installed and the project profile names an inventory]
  3. EXEC the host key of <host> in known_hosts
       ssh-keygen -F '<host>' -f ~/.ssh/known_hosts  [only if ~/.ssh/known_hosts exists]  [repeated for each host in service]
  4. EXEC the kubeconfig contexts
       kubectl config get-contexts -o name
  5. WRITE infra.repos in <scratch>/empty-config.yaml
The command also reads the files of the checkout and the devops ssh key folder.

Gaps for homelab

  • Row 2: no .devops/project.toml; the row lists the 5 values to commit.
  • Row 8: no collections/requirements.yml; the plays use ansible.posix, community.general and kubernetes.core (homelab#8).
  • Row 12: no kube context in the entry; a person adds --kube-context homelab-k3s.
  • Row 13: no CI workflow (homelab#8).
  • Row 14: no host sets devops_infra_node_service (homelab#21).
  • Row 15: 14 tasks with check_mode: false, as the design counted.
  • Row 16: 16 Makefile targets that devops infra node replaces (homelab#22).
  • Host key checks are on at f5961bd (homelab#24 merged), and ~/.ssh/known_hosts holds the key of each host in service.

Checks run on the branch

  • uv run devops ci --check --only lint,format,docs,constructs,openspec,test-tree: pass.
  • uv run pytest on tests/infra, tests/project, tests/config, tests/core/test_caller.py, tests/tools_lock, tests/commands (infra, install-tools, help), tests/telemetry, tests/ai/mcp, tests/invariants, tests/docs, tests/research: 2557 passed.
  • mypy on the 15 changed source files: no issues.
  • devops install-tools --tool ansible-core, then ansible-runner --version: 2.4.3; devops install-tools --check --tool ansible-core: linked at the locked version.

The runner image table leaves ansible-core out with its reason, and the
Renovate and variable tables of the tests name the new pins and the
three infra variables.
@dan-petty
dan-petty force-pushed the feat/5121-infra-onboard branch from 147dc47 to 86e2c38 Compare November 12, 2026 17:14
@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 17:21
@dan-petty
dan-petty merged commit ad782a6 into main Nov 12, 2026
32 checks passed
@dan-petty
dan-petty deleted the feat/5121-infra-onboard branch November 12, 2026 17:24
dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.121.0](v0.120.1...v0.121.0)
(2026-11-12)


### Features

* **infra:** onboard an Ansible infra repo
([#5149](#5149))
([ad782a6](ad782a6))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/infra Docker container images, DevContainers, and infrastructure tooling type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(infra): onboard an Ansible infra repo

1 participant