One Ansible repository for the whole rack
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.
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
[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/resticThe playbook
- name: Every machine
hosts: all
roles:
- common
- name: Proxmox nodes
hosts: pve
roles:
- restic
- name: The NAS
hosts: storage
roles:
- nfs
- restic_pruneThe restic role
Each role is what one chapter typed by hand. This is chapter 4 as tasks:
- 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: trueA dry run first
$ 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=0One 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.
subscribe
New entries and the next chapter by mail, nothing else.