diff --git a/freebsd-update.yml b/freebsd-update.yml new file mode 100644 index 0000000..0d4a3c2 --- /dev/null +++ b/freebsd-update.yml @@ -0,0 +1,62 @@ +--- +- hosts: freebsdservers + gather_facts: true + become: true + vars: + jails: + - aa-torrenting + - basejail + + tasks: + - name: Update all installed packages + community.general.pkgng: + name: "*" + state: latest + + - name: Update all installed packages in jails + community.general.pkgng: + name: "*" + state: latest + jail: "{{ item }}" + with_items: "{{ jails }}" + + - name: Run freebsd-update fetch + ansible.builtin.command: freebsd-update fetch + + - name: Check if updates are ready + ansible.builtin.command: freebsd-update updatesready + register: updatesready + + - name: Upgrade the system + ansible.builtin.command: freebsd-update install + register: upgraded + when: + - updatesready.rc == 0 + + - name: Reboot may be necessary + ansible.builtin.debug: + msg: "A system reboot may be necessary." + when: + - upgraded.rc == 0 + + - name: Run freebsd-update fetch on jails + ansible.builtin.command: "freebsd-update fetch -j {{ item }}" + with_items: "{{ jails }}" + + - name: Check if updates are ready in jails + ansible.builtin.command: "freebsd-update updatesready -j {{ item }}" + register: updatesready_jails + with_items: "{{ jails }}" + + - name: Upgrade the jails + ansible.builtin.command: "freebsd-update install -j {{ items }}" + register: upgraded_jails + with_items: "{{ jails }}" + when: + - updatesready_jails.rc == 0 + + - name: Reboot of jail may be necessary + ansible.builtin.debug: + msg: "A system reboot may be necessary for this jail." + when: + - upgraded_jails.rc == 0 diff --git a/inventory.yml b/inventory.yml index 9d74b62..8f95d60 100644 --- a/inventory.yml +++ b/inventory.yml @@ -13,6 +13,13 @@ debianservers: ansible_host: headscale.headscale.moonshadow.dev ansible_python_interpreter: /usr/bin/python3 +freebsdservers: + hosts: + nas: + ansible_user: jas + ansible_host: nas.headscale.moonshadow.dev + ansible_python_interpreter: /usr/local/bin/python3 + promservers: hosts: desktop: