From b03f7a47e04f0df1b54497e74bb3581cf501e863 Mon Sep 17 00:00:00 2001 From: DerLinkman Date: Fri, 2 Feb 2024 21:24:08 +0100 Subject: [PATCH] Initial commit --- .gitignore | 3 +++ deploy-keys/deploy-keys.yaml | 19 +++++++++++++++++++ deploy-keys/vars/public-keys.env | 4 ++++ reboot-if-needed/reboot-if-needed.yaml | 12 ++++++++++++ update-os/update.yaml | 15 +++++++++++++++ update-to-deb12/update-to-deb12.yaml | 25 +++++++++++++++++++++++++ upgrade-alpine/upgrade-alpine.yaml | 16 ++++++++++++++++ 7 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 deploy-keys/deploy-keys.yaml create mode 100644 deploy-keys/vars/public-keys.env create mode 100644 reboot-if-needed/reboot-if-needed.yaml create mode 100644 update-os/update.yaml create mode 100644 update-to-deb12/update-to-deb12.yaml create mode 100644 upgrade-alpine/upgrade-alpine.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..204d0a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +ansible.cfg +hosts +proxmox.* \ No newline at end of file diff --git a/deploy-keys/deploy-keys.yaml b/deploy-keys/deploy-keys.yaml new file mode 100644 index 0000000..b846740 --- /dev/null +++ b/deploy-keys/deploy-keys.yaml @@ -0,0 +1,19 @@ +--- +- name: Add SSH Keys on Hosts + hosts: all + vars_files: + - vars/public-keys.env + tasks: + - name: Get SSH Keys + ansible.builtin.shell: cat /root/.ssh/authorized_keys + register: key_output + + - name: Add SSH Keys + with_items: + - "{{ ssh_keys }}" + ansible.builtin.shell: | + cat <> /root/.ssh/authorized_keys + ### Managed with Ansible {{ ansible_date_time.day }}-{{ ansible_date_time.month }}-{{ ansible_date_time.year }} ### + {{ item }} + EOF + when: key_output.stdout.find('{{ item }}') == -1 \ No newline at end of file diff --git a/deploy-keys/vars/public-keys.env b/deploy-keys/vars/public-keys.env new file mode 100644 index 0000000..cc9b1eb --- /dev/null +++ b/deploy-keys/vars/public-keys.env @@ -0,0 +1,4 @@ +--- +ssh_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDGrrd0B5UIj2bkpqLbj1NVAKGzh0T4X20jZGaXYLA18MHK7LqAunTZb231JwdjhrzHPy826/fwn7NU/GKAZJkk3tEi1nXI8bFUGbtCMDGh6VGTWujGzhVHnNDh+jh2t5uJe0E8Scnrn9sD4lFeMeihbBdjv6GHYYFWVkKXZ0kgLnD+wjZkQLTIgLlHocb/gPODjDWsArto5fc9YOZoPgM9XkveojXWMbPLspcD6CMysOObMwdthW0eRDoI380Ol2Pe/fT0x5bSBwUTCBRrhQUO/p3KlwYQe/sO9t//Z5vBF3XBkLCm5Y7O/Mx5FpAPjHQPHT8E9m0k863pcSWwoT/QaU1f5xQl/2RGPS8GgWmKFzHuVM/sMmVGbp7S6YMTgPh6GTWggeYCjruPZNnjUt3V2cPLe97I8dPrc/GP+dHPc5uF5w8bMyZOC21yndCwocmPOM3LYyxTggbtZctr7WXGx6Zqc1HQ+EL8iPteIiCWYT7wwW3sol3LUY/HgB2nChU= root@ansible-semaphore + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgNIBhFlWa82Q0f2EnPcpHsP5JmmGpxyWVUhfpWV3KLvNkl63aGBRZW1gEoda1P5j/ESkwHntVeen8vHjqlQ/ZB9Bs3XtWwsvtS8gfyCoRqgQVQ31T52KVT3QL8/ep0RYwG+3VbE9yvQgeELJETzpXWoyY9+RrPG1gMdArML5cO1NCizShsxNKgHe75+GjCdEe3HMUuCcfJ23JqxPqgA5HoGW1mGsbI1LnLn1fqgmywSKET5LpkKHtHjrXFtQi2NKEnZ3RNxgh60v4amvMKLsxBk1vAn40X+ZeLJwNMpMHep2IzvO67inlj9iWaY5VXjZznLXzd85zhTO3eDv+yAp9 linkman-pc-2022 diff --git a/reboot-if-needed/reboot-if-needed.yaml b/reboot-if-needed/reboot-if-needed.yaml new file mode 100644 index 0000000..9caa1ef --- /dev/null +++ b/reboot-if-needed/reboot-if-needed.yaml @@ -0,0 +1,12 @@ +--- +- name: check if system reboot is required + hosts: all + tasks: + - name: check if system reboot is required + stat: + path: /var/run/reboot-required + register: reboot_required + - name: reboot machine + reboot: + reboot_timeout: 3600 + when: reboot_required.stat.exists \ No newline at end of file diff --git a/update-os/update.yaml b/update-os/update.yaml new file mode 100644 index 0000000..7177134 --- /dev/null +++ b/update-os/update.yaml @@ -0,0 +1,15 @@ +--- +- name: Update Systems + hosts: all + tasks: + - name: Run Apt Update and upgrade where needed + apt: + update_cache: yes + upgrade: yes + when: ansible_distribution == 'Debian' + + - name: Run APK update and upgrade + apk: + update_cache: yes + upgrade: true + when: ansible_distribution == 'Alpine' \ No newline at end of file diff --git a/update-to-deb12/update-to-deb12.yaml b/update-to-deb12/update-to-deb12.yaml new file mode 100644 index 0000000..090f21f --- /dev/null +++ b/update-to-deb12/update-to-deb12.yaml @@ -0,0 +1,25 @@ +--- +- name: Update to Debian 12 + hosts: all + tasks: + - name: Run Pre Update and Upgrade before Dist Upgrade + apt: + update_cache: yes + upgrade: yes + when: ansible_distribution == 'Debian' + + - name: Replace "bullseye" with "bookworm" in sources.list + replace: + backup: yes + path: /etc/apt/sources.list + regexp: 'bullseye' + replace: 'bookworm' + when: ansible_distribution == 'Debian' + + - name: Replace "bullseye" with "bookworm" in sources.list.d/docker + replace: + backup: yes + path: /etc/apt/sources.list.d/docker.list + regexp: 'bullseye' + replace: 'bookworm' + when: ansible_distribution == 'Debian' diff --git a/upgrade-alpine/upgrade-alpine.yaml b/upgrade-alpine/upgrade-alpine.yaml new file mode 100644 index 0000000..b428168 --- /dev/null +++ b/upgrade-alpine/upgrade-alpine.yaml @@ -0,0 +1,16 @@ +- name: Update to newest Alpine + hosts: all + tasks: + - name: Run APK update + apk: + update_cache: yes + upgrade: true + when: ansible_distribution == 'Alpine' + + - name: Update Alpine versions + replace: + backup: yes + path: "/etc/apk/repositories" + regexp: 'v\d+\.\d+' + replace: 'v3.18' + when: ansible_distribution == 'Alpine' \ No newline at end of file