Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Updating My Home Lab using Ansible

September 26, 2023 — Gregg Szumowski

I have a variety of Raspberry Pis that I use for various tasks like my Tiny-Tiny RSS server, Gitea server, and Calibre server among other things. In order to keep them updated I use Ansible.

My update script is fairly simple:

$ cat update-pis.sh 
#!/bin/bash
ansible-playbook ./playbooks/apt.yml --user memyselfandi \
     --ask-pass --ask-become-pass -i ./inventory/hosts $@

The YAML playbook is likewise very simple:

$ cat ./playbooks/apt.yml 
- hosts: "*"
  become: yes
  tasks:
  - name: Update System Package Cache (apt)
    apt:
      update_cache: yes
      upgrade: 'yes'
 
  - name: Upgrade System Packages (apt)
    apt: upgrade=full

  - name: Remove unused dependencies
    apt: autoremove=true

  - name: Check if reboot is required
    shell: "[ -f /var/run/reboot-required ]"
    failed_when: False
    register: reboot_required
    changed_when: reboot_required.rc == 0
    notify: reboot

  handlers:
  - name: reboot
    command: /sbin/reboot

Although I can run this in a cronjob, I tend to run it manually (for now). I’m thinking about doing some major revisions to my Pi configuration anyway. Stay tuned for more on that subject.

Tags: cli, ansible, motd

Ansible Cheatsheet

August 05, 2023 — Gregg Szumowski

Ping all hosts:

$ ansible all -i hosts -m ping

Ping a specific host:

$ ansible raspberry-pi -m ping

Check uptime on all hosts:

$ ansible -m shell -a 'uptime' all

Check uname on all hosts:

$ ansible -m shell -a 'uname -a' all

Run playbook on more than one host:

$ ansible-playbook playbook1.yml -l 'host1.com,host2com'

Enable Debug and Increase Verbosity in Ansible

$ ANSIBLE_DEBUG=true ANSIBLE_VERBOSITY=4 ansible-playbook playbook.yml

Tags: cli, ansible, motd