> ## Content Index
> Fetch the complete content index at: https://logbuch-homelab.nichedthemes.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# One Ansible repository for the whole rack
- URL: https://logbuch-homelab.nichedthemes.com/one-ansible-repository-for-the-rack/
- Published: 2026-09-13T08:00:00.000Z
- Updated: 2026-09-13T08:00:00.000Z
- Description: Four chapters of commands, typed once per machine. This one puts them into loft-ansible, so a rebuilt node gets the same setup with one command.
- Author: Tomasz Wieland
- Tags: Homelab, Proxmox, Rebuilding the rack, loft-ansible, #Import 2026-11-19 07:37

Four chapters of commands, typed once per machine. This chapter puts them into one Ansible repository, `loft-ansible`, so a new node or a rebuilt NAS gets the same setup with one command. It is at v1.2.0 as this goes out, and releases get their own notes from now on.

## The inventory

```ini
[pve]
pve-1 ansible_host=10.0.10.11
pve-2 ansible_host=10.0.10.12
pve-3 ansible_host=10.0.10.13

[storage]
nas ansible_host=10.0.10.20

[all:vars]
ansible_user=root
restic_repo=sftp:restic@nas:/srv/restic
```

## The playbook

```yaml
- name: Every machine
  hosts: all
  roles:
    - common

- name: Proxmox nodes
  hosts: pve
  roles:
    - restic

- name: The NAS
  hosts: storage
  roles:
    - nfs
    - restic_prune
```

## The restic role

Each role is what one chapter typed by hand. This is chapter 4 as tasks:

```yaml
- name: Install restic
  ansible.builtin.apt:
    name: restic

- name: Place the repository password
  ansible.builtin.copy:
    content: "{{ restic_password }}"
    dest: /root/.restic-password
    mode: "0600"

- name: Install the backup script
  ansible.builtin.template:
    src: backup.sh.j2
    dest: /usr/local/bin/backup.sh
    mode: "0700"

- name: Install the service and the timer
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: /etc/systemd/system/
  loop: [restic-backup.service, restic-backup.timer]

- name: Enable the nightly timer
  ansible.builtin.systemd_service:
    name: restic-backup.timer
    enabled: true
    state: started
    daemon_reload: true
```

## A dry run first

```console
$ ansible-playbook -i hosts.ini site.yml --check --diff
PLAY RECAP *********************************************************
nas     : ok=9   changed=0  unreachable=0  failed=0
pve-1   : ok=12  changed=0  unreachable=0  failed=0
pve-2   : ok=12  changed=1  unreachable=0  failed=0
pve-3   : ok=12  changed=0  unreachable=0  failed=0
```

One change, on pve-2: a `Nice=` line in the restic service that I had added by hand there and nowhere else. The role has it now, on all three.

The repository runs from my laptop. Nothing in the rack needs Ansible installed, only SSH and Python.