Compare commits

...

8 Commits

11 changed files with 80 additions and 8 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
**/*venv
*.log

View File

@@ -1,8 +1,8 @@
---
- name: Update the system
hosts: pibox
become: true
hosts: pibox
roles:
- role: apt-update-system

View File

@@ -1,13 +1,13 @@
---
- name: Install Packages
- name: Remove Packages
become: true
hosts: pibox
tasks:
- name: Loop over packages_to_install and install them
ansible.builtin.include_role:
name: apt-install-package
loop: packages_to_install
loop: "{{ packages_to_install }}"
loop_control:
loop_var: package

View File

@@ -0,0 +1,14 @@
---
- name: Install Packages
become: true
hosts: pibox
tasks:
- name: Loop over packages_to_remove and remove them
ansible.builtin.include_role:
name: apt-remove-package
loop: "{{ packages_to_remove }}"
loop_control:
loop_var: package
...

View File

@@ -1,6 +1,6 @@
pibox:
hosts:
pibox-01.c0de.online
pibox-02.c0de.online
pibox-01.c0de.online:
pibox-02.c0de.online:
vars:
ansible_user: c0de

14
ansible/play.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
playbook_name=$1
inventory_path="./inventories/"
log_path="../logs"
log_file="${log_path}/${playbook_name}.log"
mkdir -p "${log_path}"
echo "${playbook_name} started at $(date)" | tee -a "${log_file}"
{ time ansible-playbook -i "${inventory_path}" "${playbook_name}" ; } 2>&1 | tee -a "${log_file}"
echo "${playbook_name} finished at $(date)" | tee -a "${log_file}"

View File

@@ -5,6 +5,6 @@
update_cache: true
name: "{{ package }}"
state: latest
failed_when: package is unset
failed_when: package is undefined
...

View File

@@ -0,0 +1,10 @@
---
- name: "Remove {{ package }}"
ansible.builtin.apt:
update_cache: true
name: "{{ package }}"
state: absent
failed_when: package is undefined
...

View File

@@ -14,6 +14,9 @@
ansible.builtin.apt:
autoclean: true
autoremove: true
- name: purge any left over files
ansible.builtin.apt:
purge: true
...

View File

@@ -7,6 +7,8 @@ Some ansible playbooks to manage a [pibox](https://pibox.io) in various ways
1. Internet connection
1. Python 3 on Linux (or WSL)
1. One or more PiBoxes that you don't want to manage through [KubeSail](https://kubesail.com)
- I recommend [installing the latest version](https://docs.kubesail.com/guides/pibox/rpiboot/) before proceeding
- _Note: There is a bug where the ssh server won't start. Fix outlined below._
## Getting Started
@@ -16,5 +18,33 @@ Some ansible playbooks to manage a [pibox](https://pibox.io) in various ways
1. Enter the virtual environment: `source .venv/bin/activate`
1. (optional) Upgrade PIP: `pip3 install --upgrade pip`
1. Install ansible: `pip3 install -r requirements.txt`
1. Configure Inventory, host vars and group vars
1. You probably don't have my domain name on your network lol
1. Configure [inventory](./ansible/inventories/inventory.yml)
- You probably don't have my domain name on your network lol
1. Ping your hosts: `ansible -i ansible/inventories/inventory.yml all -m ping`
- If you can't resolve any hosts, check DNS. It's always DNS.
1. Proceed to running playbooks
## Running Playbooks
It's recommended to use [`play.sh`](./ansible/play.sh) as it will automatically create log files for the playbooks that you execute.
Its usage is: `./play.sh <playbook-name>`
## Fixing no SSH on latest version
During install of the custom image, `pi flasher` allowed me to configure things like the hostname, ssid, my ssh key, my user account. This sets up a script that runs when the pi reboots for the first time after install.
1. Mount the pi's `/boot` volume (it should be in your file manager somewhere)
1. Edit the `initial-boot.sh` (or similar named script)
1. Add `ssh-keygen -A` somewhere in the file
1. Save and close the file
1. Safely unmount the pi's `/boot`
1. Done! The ssh server is now functional
_Alternatively, you can wait for the system to boot with a keyboard and monitor connected and:_
- _login;_
- _open a terminal;_
- _run `sudo ssh-keygen -A`;_
- _then `sudo systemctl enable --now ssh`._