From 5528de7414ad1a69e7388487bc8d1bc347530605 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 22 Jun 2025 17:11:01 +0200 Subject: [PATCH 01/10] Update inventory --- Inventory/hosts.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Inventory/hosts.yaml b/Inventory/hosts.yaml index b587eaa..4568980 100644 --- a/Inventory/hosts.yaml +++ b/Inventory/hosts.yaml @@ -27,8 +27,6 @@ all: compute-1: debian: hosts: - pve-R730-3GDWF82: - truenas: mailcow: docker: hosts: From 3c7ce0f8c520891b804c0b652f7462353853132f Mon Sep 17 00:00:00 2001 From: max Date: Sun, 22 Jun 2025 18:39:27 +0200 Subject: [PATCH 02/10] Added truenas update && playbook for fedora and debian hosts --- Inventory/hosts.yaml | 5 +- .../update-debian-hosts.yaml} | 3 +- .../update-fedora-hosts.yaml} | 0 Playbooks/machine-update/update-machines.yaml | 10 +++ Playbooks/truenas/README.md | 2 + Playbooks/truenas/update-truenas-task.yaml | 61 +++++++++++++++++++ Playbooks/truenas/update-truenas.yaml | 14 +++++ 7 files changed, 93 insertions(+), 2 deletions(-) rename Playbooks/{update-apt.yaml => machine-update/update-debian-hosts.yaml} (62%) rename Playbooks/{update-dnf.yaml => machine-update/update-fedora-hosts.yaml} (100%) create mode 100644 Playbooks/machine-update/update-machines.yaml create mode 100644 Playbooks/truenas/README.md create mode 100644 Playbooks/truenas/update-truenas-task.yaml create mode 100644 Playbooks/truenas/update-truenas.yaml diff --git a/Inventory/hosts.yaml b/Inventory/hosts.yaml index 4568980..74bf383 100644 --- a/Inventory/hosts.yaml +++ b/Inventory/hosts.yaml @@ -34,4 +34,7 @@ all: compute-1: pve: hosts: - pve-R730-3GDWF82: \ No newline at end of file + pve-R730-3GDWF82: + nas: + hosts: + truenas: \ No newline at end of file diff --git a/Playbooks/update-apt.yaml b/Playbooks/machine-update/update-debian-hosts.yaml similarity index 62% rename from Playbooks/update-apt.yaml rename to Playbooks/machine-update/update-debian-hosts.yaml index 03f05fb..7a3c803 100644 --- a/Playbooks/update-apt.yaml +++ b/Playbooks/machine-update/update-debian-hosts.yaml @@ -5,4 +5,5 @@ - name: update APT packages apt: upgrade: yes - update_cache: yes \ No newline at end of file + update_cache: yes + cache_valid_time: 86400 \ No newline at end of file diff --git a/Playbooks/update-dnf.yaml b/Playbooks/machine-update/update-fedora-hosts.yaml similarity index 100% rename from Playbooks/update-dnf.yaml rename to Playbooks/machine-update/update-fedora-hosts.yaml diff --git a/Playbooks/machine-update/update-machines.yaml b/Playbooks/machine-update/update-machines.yaml new file mode 100644 index 0000000..c55ca56 --- /dev/null +++ b/Playbooks/machine-update/update-machines.yaml @@ -0,0 +1,10 @@ +--- +- hosts: fedora + tasks: + - name: Update fedora hosts + include_tasks: update-fedora-hosts.yaml + +- hosts: debian + tasks: + - name: Update debian hosts + include_tasks: update-debian-hosts.yaml diff --git a/Playbooks/truenas/README.md b/Playbooks/truenas/README.md new file mode 100644 index 0000000..cae8aba --- /dev/null +++ b/Playbooks/truenas/README.md @@ -0,0 +1,2 @@ +# Git +https://github.com/fanuelsen/ansible/tree/master/ansible-truenas-api \ No newline at end of file diff --git a/Playbooks/truenas/update-truenas-task.yaml b/Playbooks/truenas/update-truenas-task.yaml new file mode 100644 index 0000000..6d4992a --- /dev/null +++ b/Playbooks/truenas/update-truenas-task.yaml @@ -0,0 +1,61 @@ +- name: Checks if there is an update available from update server. + uri: + method: POST + url: https://{{ item.ip }}/api/v2.0/update/check_available + return_content: true + validate_certs: '{{ item.validate_certs }}' + headers: + Content-Type: application/json + Authorization: 'Bearer {{ item.token }}' + register: truenas_pending_updates + +- name: Downloads (if not already in cache) and apply an update. + uri: + method: POST + url: https://{{ item.ip }}/api/v2.0/update/update + return_content: true + validate_certs: '{{ item.validate_certs }}' + headers: + Content-Type: application/json + Authorization: 'Bearer {{ item.token }}' + when: "truenas_pending_updates.json.status == 'AVAILABLE'" + +- name: Wait for update to finish. + uri: + method: POST + url: https://{{ item.ip }}/api/v2.0/update/check_available + return_content: true + validate_certs: '{{ item.validate_certs }}' + headers: + Content-Type: application/json + Authorization: 'Bearer {{ item.token }}' + register: truenas_reboot_required + when: "truenas_pending_updates.json.status == 'AVAILABLE' or truenas_pending_updates.json.status == 'REBOOT_REQUIRED'" + until: "(truenas_reboot_required.json|default(dict(status=WAITING))).status == 'REBOOT_REQUIRED'" + retries: 20 + delay: 30 + +- name: Reboot host + uri: + method: POST + url: https://{{ item.ip }}/api/v2.0/system/reboot + return_content: true + validate_certs: '{{ item.validate_certs }}' + headers: + Content-Type: application/json + Authorization: 'Bearer {{ item.token }}' + when: truenas_reboot_required.json.status | default (false) == 'REBOOT_REQUIRED' + +- name: Returns whether the system completed boot and is ready to use. + uri: + method: GET + url: https://{{ item.ip }}/api/v2.0/system/state + return_content: true + validate_certs: '{{ item.validate_certs }}' + headers: + Content-Type: application/json + Authorization: 'Bearer {{ item.token }}' + register: truenas_system_ready + until: truenas_system_ready.content == '"READY"' + retries: 20 + delay: 30 \ No newline at end of file diff --git a/Playbooks/truenas/update-truenas.yaml b/Playbooks/truenas/update-truenas.yaml new file mode 100644 index 0000000..8e4a665 --- /dev/null +++ b/Playbooks/truenas/update-truenas.yaml @@ -0,0 +1,14 @@ +--- +- hosts: truenas + gather_facts: false + + vars: + sites: + - ip: 192.168.3.1 + token: 1-gAIQbRICSPPqM1JCsfofc8gJgLvV8SglXV2xemYzBr2rzdZvQd5J0pMYeG45Jiqx + validate_certs: false + + tasks: + - name: update-truenas-api + include_tasks: update-truenas-task.yml + loop: '{{ sites }}' \ No newline at end of file From 2d4a85826dcc9b4518b80451a6f3410fcea5b759 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 22 Jun 2025 18:45:41 +0200 Subject: [PATCH 03/10] Fixed include_task --- Playbooks/machine-update/update-debian-hosts.yaml | 14 +++++--------- Playbooks/machine-update/update-fedora-hosts.yaml | 12 ++++-------- Playbooks/machine-update/update-machines.yaml | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Playbooks/machine-update/update-debian-hosts.yaml b/Playbooks/machine-update/update-debian-hosts.yaml index 7a3c803..b0348d6 100644 --- a/Playbooks/machine-update/update-debian-hosts.yaml +++ b/Playbooks/machine-update/update-debian-hosts.yaml @@ -1,9 +1,5 @@ ---- - -- hosts: debian - tasks: - - name: update APT packages - apt: - upgrade: yes - update_cache: yes - cache_valid_time: 86400 \ No newline at end of file +- name: update APT packages + apt: + upgrade: yes + update_cache: yes + cache_valid_time: 86400 \ No newline at end of file diff --git a/Playbooks/machine-update/update-fedora-hosts.yaml b/Playbooks/machine-update/update-fedora-hosts.yaml index 94cc1fe..ea0d2e7 100644 --- a/Playbooks/machine-update/update-fedora-hosts.yaml +++ b/Playbooks/machine-update/update-fedora-hosts.yaml @@ -1,8 +1,4 @@ ---- - -- hosts: fedora - tasks: - - name: Upgrade all packages - ansible.builtin.dnf: - name: "*" - state: latest \ No newline at end of file +- name: Upgrade all packages + ansible.builtin.dnf: + name: "*" + state: latest \ No newline at end of file diff --git a/Playbooks/machine-update/update-machines.yaml b/Playbooks/machine-update/update-machines.yaml index c55ca56..7deb571 100644 --- a/Playbooks/machine-update/update-machines.yaml +++ b/Playbooks/machine-update/update-machines.yaml @@ -2,9 +2,9 @@ - hosts: fedora tasks: - name: Update fedora hosts - include_tasks: update-fedora-hosts.yaml + include_tasks: update-fedora-hosts.yaml - hosts: debian tasks: - name: Update debian hosts - include_tasks: update-debian-hosts.yaml + include_tasks: update-debian-hosts.yaml From 4f2f3c7bf123cd140957862f11f16ce4fbab48e8 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 22 Jun 2025 18:54:08 +0200 Subject: [PATCH 04/10] Updated ssh port for host network & added readme for info --- Inventory/hosts.yaml | 1 + Playbooks/machine-update/README.md | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 Playbooks/machine-update/README.md diff --git a/Inventory/hosts.yaml b/Inventory/hosts.yaml index 74bf383..463139d 100644 --- a/Inventory/hosts.yaml +++ b/Inventory/hosts.yaml @@ -8,6 +8,7 @@ all: ansible_user: truenas_admin network: ansible_host: 192.168.1.253 + ansible_port: 9 ansible_user: root mailcow: ansible_host: 192.168.1.200 diff --git a/Playbooks/machine-update/README.md b/Playbooks/machine-update/README.md new file mode 100644 index 0000000..f896b31 --- /dev/null +++ b/Playbooks/machine-update/README.md @@ -0,0 +1,7 @@ +# Required packages +### Fedora + +- python3-libdnf5 +```shell +dnf install python3-libdnf5 +``` From fab13641bb9c65ce2f238840d99c9372d21b1f9c Mon Sep 17 00:00:00 2001 From: max Date: Sun, 22 Jun 2025 20:17:44 +0200 Subject: [PATCH 05/10] Fix truenas update --- .../{update-truenas-task.yaml => update-truenas-tasks.yaml} | 0 Playbooks/truenas/update-truenas.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename Playbooks/truenas/{update-truenas-task.yaml => update-truenas-tasks.yaml} (100%) diff --git a/Playbooks/truenas/update-truenas-task.yaml b/Playbooks/truenas/update-truenas-tasks.yaml similarity index 100% rename from Playbooks/truenas/update-truenas-task.yaml rename to Playbooks/truenas/update-truenas-tasks.yaml diff --git a/Playbooks/truenas/update-truenas.yaml b/Playbooks/truenas/update-truenas.yaml index 8e4a665..e1f816b 100644 --- a/Playbooks/truenas/update-truenas.yaml +++ b/Playbooks/truenas/update-truenas.yaml @@ -10,5 +10,5 @@ tasks: - name: update-truenas-api - include_tasks: update-truenas-task.yml + include_tasks: update-truenas-tasks.yaml loop: '{{ sites }}' \ No newline at end of file From aac6953db96a8dc8813f8fc575a5430ed1d291cc Mon Sep 17 00:00:00 2001 From: max Date: Thu, 10 Jul 2025 17:06:45 +0200 Subject: [PATCH 06/10] Test --- Playbooks/truenas/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Playbooks/truenas/README.md b/Playbooks/truenas/README.md index cae8aba..903dfc3 100644 --- a/Playbooks/truenas/README.md +++ b/Playbooks/truenas/README.md @@ -1,2 +1,4 @@ # Git -https://github.com/fanuelsen/ansible/tree/master/ansible-truenas-api \ No newline at end of file +https://github.com/fanuelsen/ansible/tree/master/ansible-truenas-api + +Test change \ No newline at end of file From 628a57648ce212315b405f56218210ec33b8d09f Mon Sep 17 00:00:00 2001 From: max Date: Thu, 10 Jul 2025 17:07:10 +0200 Subject: [PATCH 07/10] Test --- Playbooks/truenas/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Playbooks/truenas/README.md b/Playbooks/truenas/README.md index 903dfc3..cae8aba 100644 --- a/Playbooks/truenas/README.md +++ b/Playbooks/truenas/README.md @@ -1,4 +1,2 @@ # Git -https://github.com/fanuelsen/ansible/tree/master/ansible-truenas-api - -Test change \ No newline at end of file +https://github.com/fanuelsen/ansible/tree/master/ansible-truenas-api \ No newline at end of file From 96e5f1c09da61a6f676501cc32440d9cdc9ae470 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 10 Jul 2025 18:02:08 +0200 Subject: [PATCH 08/10] Update python interpreter for hosts --- Inventory/host_vars/all.yaml | 1 + 1 file changed, 1 insertion(+) create mode 100644 Inventory/host_vars/all.yaml diff --git a/Inventory/host_vars/all.yaml b/Inventory/host_vars/all.yaml new file mode 100644 index 0000000..b4a2c4f --- /dev/null +++ b/Inventory/host_vars/all.yaml @@ -0,0 +1 @@ +ansible_python_interpreter: /usr/bin/python3 \ No newline at end of file From c7c56b8cbdb6b414b14794adf0d87c93bba9b03d Mon Sep 17 00:00:00 2001 From: max Date: Thu, 10 Jul 2025 18:04:35 +0200 Subject: [PATCH 09/10] Move all.yaml to groupp_vars --- Inventory/{host_vars => group_vars}/all.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Inventory/{host_vars => group_vars}/all.yaml (100%) diff --git a/Inventory/host_vars/all.yaml b/Inventory/group_vars/all.yaml similarity index 100% rename from Inventory/host_vars/all.yaml rename to Inventory/group_vars/all.yaml From d30e4f067c5d5b854d478a2f507ca0e64e048a78 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 10 Jul 2025 18:54:05 +0200 Subject: [PATCH 10/10] Added new host 'cloud' --- Inventory/hosts.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Inventory/hosts.yaml b/Inventory/hosts.yaml index 463139d..fd5eff8 100644 --- a/Inventory/hosts.yaml +++ b/Inventory/hosts.yaml @@ -19,6 +19,9 @@ all: compute-1: ansible_host: 192.168.2.3 ansible_user: root + cloud: + ansible_host: 192.168.2.7 + ansible_user: root children: fedora: @@ -29,6 +32,7 @@ all: debian: hosts: mailcow: + cloud: docker: hosts: compute-0: