GNAI-007: Basisfunktionen für Ansible erstellt.

This commit is contained in:
2026-09-19 23:20:35 +02:00
parent 7d1a3228ef
commit de06eb6129
18 changed files with 1227 additions and 2 deletions
+140
View File
@@ -0,0 +1,140 @@
# Ansible control project
This directory contains the reproducible control project for `ghostnet-ki`.
The read-only `playbooks/preflight.yml` verifies the documented host identity
and hardware. The first writing milestone, `playbooks/host.yml`, applies a
small shared host baseline through the dedicated deployment account.
## Control-node setup
Use Python 3.12 through 3.14 and create a virtual environment at the repository
root:
```bash
python3 -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -r ansible/requirements-control.txt
```
Load the private key for the read-only `ghost-agent` account into an SSH agent.
Do not store private keys or passphrases in this repository:
```bash
ssh-add /path/to/ghost-agent-private-key
```
The workstation must already trust the verified SSH host key for `10.0.0.90`.
An unexpected host-key change must be checked through a trusted console before
continuing.
## Read-only preflight
Run the commands from the `ansible/` directory:
```bash
cd ansible
../.venv/bin/ansible-inventory --graph
../.venv/bin/ansible-playbook playbooks/preflight.yml --syntax-check
../.venv/bin/ansible-playbook playbooks/preflight.yml
```
The final recap must report `changed=0` and `failed=0`. The playbook verifies:
- hostname `ghostnet-ki`;
- Debian major version 13;
- default IPv4 address `10.0.0.90`;
- remote Python availability; and
- two AMD Navi 21 PCI devices with ID `1002:73bf`.
The inventory deliberately contains no private-key path. Each operator supplies
their authorized key through `ssh-agent` or a local Ansible override.
## One-time deployment-account bootstrap
Status 2026-09-19: The initial bootstrap has been applied to `ghostnet-ki`, and
the separate verification playbook confirmed SSH access and non-interactive
effective UID 0 with `changed=0` and `failed=0`. Run the bootstrap again only
for an intentional repair, rotation or idempotence check.
The bootstrap creates the dedicated `ansible-deploy` account. Its password is
locked, its committed public key is restricted to the LAN and WireGuard source
networks, and `/etc/sudoers.d/90-ansible-deploy` is validated with `visudo`
before installation. The account receives `NOPASSWD` root escalation because
the planned host, package, systemd and container management cannot be expressed
as a small stable command allowlist.
The matching private key stays outside this repository. On the workstation on
which the initial key was created, it is stored as:
```text
~/.ssh/id_ed25519_ghostnet_ai_ansible_deploy
```
The automation key has no interactive passphrase so a future runner can use it
non-interactively. It is protected by filesystem mode `0600`, SSH source-network
restrictions and the dedicated account. Compromise of this private key would
nevertheless grant root-equivalent deployment access; rotate it when moving the
deployment identity to the runner or after any suspected disclosure.
Load the existing personal administrator key into an SSH agent, then run the
bootstrap interactively from the `ansible/` directory. Ansible will ask for the
personal administrator's existing sudo password:
```bash
ssh-add /path/to/personal-ghost-private-key
../.venv/bin/ansible-playbook \
--inventory inventories/bootstrap/hosts.yml \
playbooks/bootstrap-deploy-account.yml \
--ask-become-pass
```
Do not send the password through chat, store it in Git, or place it in a shell
history entry. The bootstrap is idempotent; a second run should report no
changes.
After a successful bootstrap, verify the new account independently:
```bash
../.venv/bin/ansible-playbook \
playbooks/verify-deploy-access.yml \
--extra-vars ansible_user=ansible-deploy \
--private-key ~/.ssh/id_ed25519_ghostnet_ai_ansible_deploy
```
The verification must report `changed=0` and `failed=0`. It confirms both the
unprivileged SSH identity and non-interactive escalation to effective UID 0.
## Shared host baseline
The host baseline is common to Production and Testing. It verifies the target
identity and at least 100 GiB free on the root filesystem, then manages these
root-owned directory roots:
```text
/etc/ghostnet-ai/{production,testing}
/var/lib/ghostnet-ai/{production,testing,shared}
```
It does not install software or start services. Use the dedicated host
inventory and supply the private deployment key outside the repository:
```bash
../.venv/bin/ansible-playbook \
--inventory inventories/host/hosts.yml \
playbooks/host.yml \
--syntax-check
../.venv/bin/ansible-playbook \
--inventory inventories/host/hosts.yml \
playbooks/host.yml \
--check --diff \
--private-key ~/.ssh/id_ed25519_ghostnet_ai_ansible_deploy
../.venv/bin/ansible-playbook \
--inventory inventories/host/hosts.yml \
playbooks/host.yml \
--private-key ~/.ssh/id_ed25519_ghostnet_ai_ansible_deploy
```
Run the final command a second time. The second recap must report `changed=0`
and `failed=0`; otherwise the role has not demonstrated convergence.
+13
View File
@@ -0,0 +1,13 @@
[defaults]
inventory = inventories/testing/hosts.yml
home = .ansible
host_key_checking = True
interpreter_python = auto_silent
local_tmp = .ansible/tmp
retry_files_enabled = False
roles_path = roles
timeout = 15
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
+1
View File
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJE3UGGHyB+CMA2sqPpI/6efn9u3eLelL2MkHqdt2naB ansible-deploy@ghostnet-control-2026-09
+8
View File
@@ -0,0 +1,8 @@
---
all:
children:
llm_servers:
hosts:
ghostnet-ki:
ansible_host: 10.0.0.90
ansible_user: ghost
+8
View File
@@ -0,0 +1,8 @@
---
all:
children:
llm_servers:
hosts:
ghostnet-ki:
ansible_host: 10.0.0.90
ansible_user: ansible-deploy
+8
View File
@@ -0,0 +1,8 @@
---
all:
children:
llm_servers:
hosts:
ghostnet-ki:
ansible_host: 10.0.0.90
ansible_user: ghost-agent
@@ -0,0 +1,98 @@
---
- name: Bootstrap the dedicated Ansible deployment account
hosts: llm_servers
become: true
gather_facts: true
vars:
ansible_deploy_user: ansible-deploy
ansible_deploy_public_key_file: >-
{{ playbook_dir }}/../files/ssh/ansible-deploy.pub
ansible_deploy_ssh_sources:
- 10.0.0.0/24
- 10.8.0.0/24
pre_tasks:
- name: Refuse to bootstrap through the target deployment account
ansible.builtin.assert:
that:
- ansible_user != ansible_deploy_user
fail_msg: >-
Run this one-time bootstrap through an existing personal administrator
account, not through {{ ansible_deploy_user }}.
- name: Verify the local deployment public key
ansible.builtin.assert:
that:
- lookup("ansible.builtin.file", ansible_deploy_public_key_file) is match("^ssh-ed25519 ")
fail_msg: >-
The expected Ed25519 public key is missing or malformed at
{{ ansible_deploy_public_key_file }}.
tasks:
- name: Create the dedicated deployment account with a locked password
ansible.builtin.user:
name: "{{ ansible_deploy_user }}"
comment: Ghostnet AI Ansible deployment account
create_home: true
home: "/home/{{ ansible_deploy_user }}"
password_lock: true
shell: /bin/bash
state: present
- name: Protect the deployment account home directory
ansible.builtin.file:
path: "/home/{{ ansible_deploy_user }}"
state: directory
owner: "{{ ansible_deploy_user }}"
group: "{{ ansible_deploy_user }}"
mode: "0750"
- name: Create the deployment SSH directory
ansible.builtin.file:
path: "/home/{{ ansible_deploy_user }}/.ssh"
state: directory
owner: "{{ ansible_deploy_user }}"
group: "{{ ansible_deploy_user }}"
mode: "0700"
- name: Install the restricted deployment public key
ansible.builtin.copy:
content: |
restrict,from="{{ ansible_deploy_ssh_sources | join(',') }}" {{ lookup('ansible.builtin.file', ansible_deploy_public_key_file) | trim }}
dest: "/home/{{ ansible_deploy_user }}/.ssh/authorized_keys"
owner: "{{ ansible_deploy_user }}"
group: "{{ ansible_deploy_user }}"
mode: "0600"
- name: Grant explicit non-interactive root escalation for Ansible
ansible.builtin.copy:
content: |
# Managed by Ghostnet AI Ansible bootstrap.
{{ ansible_deploy_user }} ALL=(root) NOPASSWD: ALL
dest: "/etc/sudoers.d/90-{{ ansible_deploy_user }}"
owner: root
group: root
mode: "0440"
validate: /usr/sbin/visudo -cf %s
- name: Read the effective deployment sudo policy
ansible.builtin.command:
argv:
- /usr/bin/sudo
- -l
- -U
- "{{ ansible_deploy_user }}"
changed_when: false
register: ansible_deploy_sudo_policy
- name: Verify non-interactive root escalation is effective
ansible.builtin.assert:
that:
- 'ansible_deploy_sudo_policy.stdout is search("NOPASSWD: ALL")'
fail_msg: >-
The deployment account exists, but its validated NOPASSWD sudo policy
is not effective.
success_msg: >-
The deployment account and its validated sudo policy are ready for
the separate access verification playbook.
+12
View File
@@ -0,0 +1,12 @@
---
- name: Apply the shared Ghostnet AI host baseline
hosts: llm_servers
become: true
gather_facts: true
gather_subset:
- min
- network
- hardware
roles:
- role: host_baseline
+60
View File
@@ -0,0 +1,60 @@
---
- name: Verify read-only access to the Ghostnet AI server
hosts: llm_servers
become: false
gather_facts: true
gather_subset:
- min
- hardware
- network
tasks:
- name: Verify the expected host identity and operating system
ansible.builtin.assert:
that:
- ansible_facts["hostname"] == "ghostnet-ki"
- ansible_facts["distribution"] == "Debian"
- ansible_facts["distribution_major_version"] == "13"
- ansible_facts["default_ipv4"]["address"] == "10.0.0.90"
- ansible_facts["python"]["version"]["major"] >= 3
fail_msg: >-
The connected host does not match the documented Ghostnet AI server
baseline. Stop before using any deployment playbook.
success_msg: The expected Debian 13 host ghostnet-ki is connected.
- name: Read the expected AMD GPU PCI devices
ansible.builtin.command:
argv:
- lspci
- -D
- -nn
- -d
- "1002:73bf"
check_mode: false
changed_when: false
register: preflight_gpu_devices
- name: Verify both documented AMD GPUs are present
ansible.builtin.assert:
that:
- preflight_gpu_devices.stdout_lines | length == 2
fail_msg: >-
Expected two AMD Navi 21 PCI devices with ID 1002:73bf, but found
{{ preflight_gpu_devices.stdout_lines | length }}.
success_msg: Both documented AMD Navi 21 PCI devices are present.
- name: Report the verified read-only baseline
ansible.builtin.debug:
msg:
hostname: "{{ ansible_facts['hostname'] }}"
operating_system: >-
{{ ansible_facts['distribution'] }}
{{ ansible_facts['distribution_version'] }}
default_ipv4: "{{ ansible_facts['default_ipv4']['address'] }}"
processor_vcpus: "{{ ansible_facts['processor_vcpus'] }}"
memory_mib: "{{ ansible_facts['memtotal_mb'] }}"
python_version: >-
{{ ansible_facts['python']['version']['major'] }}.
{{- ansible_facts['python']['version']['minor'] }}.
{{- ansible_facts['python']['version']['micro'] }}
amd_gpu_devices: "{{ preflight_gpu_devices.stdout_lines }}"
@@ -0,0 +1,41 @@
---
- name: Verify the dedicated Ansible deployment account
hosts: llm_servers
become: false
gather_facts: false
tasks:
- name: Verify Ansible module execution without privilege escalation
ansible.builtin.ping:
- name: Read the SSH account identity
ansible.builtin.command:
argv:
- /usr/bin/id
- -un
changed_when: false
register: deploy_account_identity
- name: Verify the expected SSH account
ansible.builtin.assert:
that:
- deploy_account_identity.stdout == "ansible-deploy"
fail_msg: The SSH connection did not use the ansible-deploy account.
- name: Read the effective identity through sudo
become: true
ansible.builtin.command:
argv:
- /usr/bin/id
- -u
changed_when: false
register: deploy_root_identity
- name: Verify non-interactive root escalation
ansible.builtin.assert:
that:
- deploy_root_identity.stdout == "0"
fail_msg: Non-interactive sudo did not produce effective UID 0.
success_msg: >-
The dedicated deployment account can connect and escalate privileges
non-interactively.
+2
View File
@@ -0,0 +1,2 @@
# ansible-core 2.21 supports Python 3.12 through 3.14 on the control node.
ansible-core==2.21.4
+17
View File
@@ -0,0 +1,17 @@
# Shared host baseline
The `host_baseline` role manages state shared by the Production and Testing
environments on `ghostnet-ki`.
Its first version deliberately has a narrow scope:
- refuse changes when hostname, Debian major version or primary IPv4 address
do not match the declared target;
- require at least 100 GiB free on the root filesystem; and
- create root-owned configuration and persistent-data directory roots for both
environments and future shared data.
It does not install packages, drivers, Podman or applications and does not
start or stop services. Ownership below the directory roots will be assigned
to dedicated service accounts when the corresponding application roles are
implemented.
@@ -0,0 +1,24 @@
---
host_baseline_expected_hostname: ghostnet-ki
host_baseline_expected_distribution: Debian
host_baseline_expected_distribution_major_version: "13"
host_baseline_expected_ipv4_address: 10.0.0.90
# Preserve enough headroom for host operation and controlled model handling.
host_baseline_minimum_root_free_gib: 100
host_baseline_directories:
- path: /etc/ghostnet-ai
mode: "0755"
- path: /etc/ghostnet-ai/production
mode: "0750"
- path: /etc/ghostnet-ai/testing
mode: "0750"
- path: /var/lib/ghostnet-ai
mode: "0755"
- path: /var/lib/ghostnet-ai/production
mode: "0750"
- path: /var/lib/ghostnet-ai/testing
mode: "0750"
- path: /var/lib/ghostnet-ai/shared
mode: "0755"
@@ -0,0 +1,59 @@
---
- name: Verify the target host before changing shared state
ansible.builtin.assert:
that:
- ansible_facts["hostname"] == host_baseline_expected_hostname
- ansible_facts["distribution"] == host_baseline_expected_distribution
- >-
ansible_facts["distribution_major_version"] ==
host_baseline_expected_distribution_major_version
- >-
ansible_facts["default_ipv4"]["address"] ==
host_baseline_expected_ipv4_address
fail_msg: >-
The connected host does not match the declared Ghostnet AI host. No
baseline changes may be applied.
success_msg: The expected Debian host ghostnet-ki is connected.
- name: Select the root filesystem facts
ansible.builtin.set_fact:
host_baseline_root_mount: >-
{{ (ansible_facts["mounts"]
| selectattr("mount", "equalto", "/")
| list
| first)
| default({}) }}
- name: Verify the root filesystem was discovered
ansible.builtin.assert:
that:
- host_baseline_root_mount | length > 0
- host_baseline_root_mount["size_available"] is defined
fail_msg: Root filesystem capacity could not be determined. No changes were made.
- name: Verify minimum free capacity on the shared root filesystem
ansible.builtin.assert:
that:
- >-
host_baseline_root_mount["size_available"] | int >=
host_baseline_minimum_root_free_gib | int * 1024 ** 3
fail_msg: >-
The root filesystem has only
{{ (host_baseline_root_mount["size_available"] | int / 1024 ** 3) | round(1) }}
GiB free. At least {{ host_baseline_minimum_root_free_gib }} GiB are
required before applying the shared host baseline.
success_msg: >-
The root filesystem has
{{ (host_baseline_root_mount["size_available"] | int / 1024 ** 3) | round(1) }}
GiB free.
- name: Create the shared configuration and data directory roots
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: root
group: root
mode: "{{ item.mode }}"
loop: "{{ host_baseline_directories }}"
loop_control:
label: "{{ item.path }}"