Compare commits
15
Commits
6d5f532b2b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f22821d168 | ||
|
|
7dcc71d88c | ||
|
|
622325f210 | ||
|
|
ef7047f6bc | ||
|
|
fa0bd81dd2 | ||
|
|
e03183d58f | ||
|
|
fb54627f38 | ||
|
|
84433d5cbc | ||
|
|
abdca77860 | ||
|
|
8de2386aa1 | ||
|
|
011d427182 | ||
|
|
fe3119cfaf | ||
|
|
2b2a56dbca | ||
|
|
5752e877cb | ||
|
|
4aeb08ab1f |
No files matched your search
@@ -1,4 +1,5 @@
|
||||
[defaults]
|
||||
vault_password_file = /home/justin/.ansible/vault_pass
|
||||
# (boolean) By default, Ansible will issue a warning when received from a task action (module or action plugin).
|
||||
# These warnings can be silenced by adjusting this setting to False.
|
||||
;action_warnings=True
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ ANSIBLE_CONFIG=/home/justin/Ansible/ansible.cfg
|
||||
0 5 * * * ansible-playbook /home/justin/Ansible/docker/update-docker-compose.yaml >> /home/justin/cron-logs/update-docker-compose.log 2>&1
|
||||
30 5 * * * ansible-playbook /home/justin/Ansible/docker/restart-qtorrnt.yaml >> /home/justin/cron-logs/restart-qtorrnt.log 2>&1
|
||||
0 6 * * * ansible-playbook /home/justin/Ansible/ubuntu/restart-beszel.yaml >> /home/justin/cron-logs/restart-beszel.log 2>&1
|
||||
#0 2 * * * ansible-playbook /home/justin/Ansible/ubuntu/update.yaml >> /home/justin/cron-logs/update.log 2>&1
|
||||
#0 7 * * * ansible-playbook /home/justin/Ansible/ubuntu/reboot.yaml >> /home/justin/cron-logs/reboot.log 2>&1
|
||||
0 2 * * * ansible-playbook /home/justin/Ansible/ubuntu/update.yaml >> /home/justin/cron-logs/update.log 2>&1
|
||||
0 7 * * * ansible-playbook /home/justin/Ansible/ubuntu/reboot.yaml >> /home/justin/cron-logs/reboot.log 2>&1
|
||||
0 5 * * 2 ansible-playbook /home/justin/Ansible/ubuntu/maint-clean-logs-cache.yaml >> /home/justin/cron-logs/maint-clean-logs-cache.log 2>&1
|
||||
0 0 1,15 * * ansible-playbook /home/justin/Ansible/ubuntu/fix-ssh-host-keys.yaml >> /home/justin/cron-logs/fix-ssh-host-keys.log 2>&1
|
||||
@@ -1,309 +1,57 @@
|
||||
---
|
||||
- name: Deploy Docker Compose stack with pull and restart
|
||||
hosts: killer2.ki5bhv.com
|
||||
# Nightly: pull and recreate Docker Compose stacks, then prune unused images.
|
||||
# Add or remove a stack by editing the list for its host below.
|
||||
#
|
||||
# A stack that still fails after retries does not stop the rest of that
|
||||
# host's stacks or the other hosts. Failures are listed at the end and
|
||||
# mark the host as failed in the recap.
|
||||
- name: Update Docker Compose stacks
|
||||
hosts: killer2.ki5bhv.com:docker.ki5bhv.com:proxy-server.ki5bhv.com
|
||||
become: true
|
||||
vars:
|
||||
stacks_by_host:
|
||||
killer2.ki5bhv.com:
|
||||
- /home/justin/docker/qbits
|
||||
- /home/justin/docker/homarr
|
||||
- /home/justin/docker/wireguard
|
||||
- /home/justin/docker/beszel
|
||||
- /home/justin/docker/cup
|
||||
- /home/justin/docker/ntfy
|
||||
- /home/justin/docker/vaultwarden
|
||||
- /home/justin/docker/uptime-kuma
|
||||
- /home/justin/docker/overseerr
|
||||
- /home/justin/docker/portainer
|
||||
- /home/justin/docker/it-tools
|
||||
- /home/justin/docker/termix
|
||||
- /home/justin/docker/netalertx
|
||||
- /home/justin/docker/wavelog
|
||||
- /home/justin/docker/kometa
|
||||
- /home/justin/docker/tautulli
|
||||
- /home/justin/docker/gaseous
|
||||
docker.ki5bhv.com: # capital D on this host
|
||||
- /home/justin/Docker/code-server
|
||||
- /home/justin/Docker/audio-book
|
||||
# Not listed on purpose: windows and minecraft are kept stopped
|
||||
# ("created"), and an update would start them.
|
||||
proxy-server.ki5bhv.com:
|
||||
- /home/justin/docker/nginx-proxy
|
||||
stacks: "{{ stacks_by_host[inventory_hostname] | default([]) }}"
|
||||
|
||||
tasks:
|
||||
- name: Qbits
|
||||
- name: Pull and recreate stack
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/qbits
|
||||
project_src: "{{ item }}"
|
||||
pull: always
|
||||
recreate: auto
|
||||
register: result
|
||||
loop: "{{ stacks }}"
|
||||
loop_control:
|
||||
label: "{{ item | basename }}"
|
||||
pause: 1
|
||||
register: stack_results
|
||||
retries: 3
|
||||
delay: 3
|
||||
until: result is not failed
|
||||
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: homarr
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/homarr/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: wireguard
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/wireguard/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: beszel
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/beszel/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: cup
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/cup/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: ntfy
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/ntfy/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: vaultwarden
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/vaultwarden/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: uptime-kuma
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/uptime-kuma/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: overseerr
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/overseerr/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: portainer
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/portainer/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: it-tools
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/it-tools/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: termix
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/termix/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: ntfy
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/ntfy/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: netalertx
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/netalertx/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: homarr
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/homarr/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: wireguard
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/wireguard/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: beszel
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/beszel/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: cup
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/cup/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
|
||||
- name: ntfy
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/ntfy/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: vaultwarden
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/vaultwarden/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: uptime-kuma
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/uptime-kuma/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: overseerr
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/overseerr/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: portainer
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/portainer/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: it-tools
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/it-tools/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: termix
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/termix/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: ntfy
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/ntfy/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: netalertx
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/netalertx/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: Wavelog
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/wavelog/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: Kometa
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/kometa/
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Pause
|
||||
ansible.builtin.pause:
|
||||
seconds: 1
|
||||
|
||||
- name: Tautulli
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/tautulli/
|
||||
pull: always
|
||||
recreate: auto
|
||||
delay: 5
|
||||
until: stack_results is not failed
|
||||
ignore_errors: true
|
||||
|
||||
- name: Prune non-dangling images
|
||||
community.docker.docker_prune:
|
||||
@@ -315,43 +63,12 @@
|
||||
volumes: false
|
||||
builder_cache: false
|
||||
|
||||
- name: Deploy Docker Compose stack with pull and restart
|
||||
hosts: docker.ki5bhv.com
|
||||
become: true
|
||||
tasks:
|
||||
|
||||
- name: code
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/Docker/code-server
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Prune non-dangling images
|
||||
community.docker.docker_prune:
|
||||
containers: false
|
||||
images: true
|
||||
images_filters:
|
||||
dangling: false
|
||||
networks: false
|
||||
volumes: false
|
||||
builder_cache: false
|
||||
|
||||
- name: Deploy Docker Compose stack with pull and restart
|
||||
hosts: proxy-server.ki5bhv.com
|
||||
become: true
|
||||
tasks:
|
||||
- name: nginx proxy
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/nginx-proxy
|
||||
pull: always
|
||||
recreate: auto
|
||||
|
||||
- name: Prune non-dangling images
|
||||
community.docker.docker_prune:
|
||||
containers: false
|
||||
images: true
|
||||
images_filters:
|
||||
dangling: false
|
||||
networks: false
|
||||
volumes: false
|
||||
builder_cache: false
|
||||
- name: Fail if any stack did not update
|
||||
vars:
|
||||
failed_stacks: >-
|
||||
{{ stack_results.results | selectattr('failed', 'defined')
|
||||
| selectattr('failed') | map(attribute='item')
|
||||
| map('basename') | list }}
|
||||
ansible.builtin.fail:
|
||||
msg: "Stacks that failed to update: {{ failed_stacks | join(', ') }}"
|
||||
when: failed_stacks | length > 0
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
# Installs patchman-client on every Ubuntu server and enrolls it with the
|
||||
# Patchman server on patch.ki5bhv.com. Role settings: roles/patchman_client/defaults/main.yml
|
||||
- name: Install and enroll patchman-client
|
||||
hosts: ubuntu_servers
|
||||
become: true
|
||||
roles:
|
||||
- patchman_client
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
# Patchman server URL, including the /patchman path.
|
||||
# Clients must be in a network allowed to upload (192.168.1.0/24 by default).
|
||||
patchman_server_url: "http://192.168.1.8/patchman"
|
||||
|
||||
# Comma or space delimited tags shown on the host in Patchman.
|
||||
patchman_client_tags: "Server"
|
||||
|
||||
# Options passed to curl when uploading.
|
||||
patchman_client_curl_options: "--insecure --connect-timeout 60 --max-time 300"
|
||||
|
||||
# Report protocol: 1 = text, 2 = json (needs jq and, by default, an API key).
|
||||
patchman_client_protocol: 1
|
||||
patchman_client_api_key: ""
|
||||
|
||||
# Daily report schedule. The minute is derived from the hostname so servers
|
||||
# don't all report at the same moment, but stays stable between runs.
|
||||
patchman_cron_enabled: true
|
||||
patchman_cron_hour: "2"
|
||||
patchman_cron_minute: "{{ 59 | random(seed=inventory_hostname) }}"
|
||||
|
||||
# Send a report right away when the client is installed or its config changes.
|
||||
patchman_report_on_change: true
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,5 +0,0 @@
|
||||
---
|
||||
- name: Send patchman report
|
||||
ansible.builtin.command: /usr/sbin/patchman-client
|
||||
changed_when: true
|
||||
when: patchman_report_on_change | bool
|
||||
@@ -1,54 +0,0 @@
|
||||
---
|
||||
- name: Install client dependencies
|
||||
ansible.builtin.package:
|
||||
name: "{{ ['curl'] + (['jq'] if patchman_client_protocol | int == 2 else []) }}"
|
||||
state: present
|
||||
|
||||
- name: Install cron
|
||||
ansible.builtin.package:
|
||||
name: "{{ 'cron' if ansible_facts['os_family'] == 'Debian' else 'cronie' }}"
|
||||
state: present
|
||||
when: patchman_cron_enabled | bool
|
||||
|
||||
- name: Install patchman-client script
|
||||
ansible.builtin.copy:
|
||||
src: patchman-client
|
||||
dest: /usr/sbin/patchman-client
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
notify: Send patchman report
|
||||
|
||||
- name: Create /etc/patchman
|
||||
ansible.builtin.file:
|
||||
path: /etc/patchman
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Configure patchman-client
|
||||
ansible.builtin.template:
|
||||
src: patchman-client.conf.j2
|
||||
dest: /etc/patchman/patchman-client.conf
|
||||
owner: root
|
||||
group: root
|
||||
# keep the file private when it holds an API key
|
||||
mode: "{{ '0600' if patchman_client_api_key else '0644' }}"
|
||||
notify: Send patchman report
|
||||
|
||||
# Writes the whole file so it replaces any hand-made /etc/cron.d/patchman-client
|
||||
- name: Schedule daily patchman report
|
||||
ansible.builtin.template:
|
||||
src: patchman-client.cron.j2
|
||||
dest: /etc/cron.d/patchman-client
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: patchman_cron_enabled | bool
|
||||
|
||||
- name: Remove daily patchman report schedule
|
||||
ansible.builtin.file:
|
||||
path: /etc/cron.d/patchman-client
|
||||
state: absent
|
||||
when: not patchman_cron_enabled | bool
|
||||
@@ -1,24 +0,0 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
# Patchman server
|
||||
server={{ patchman_server_url }}
|
||||
|
||||
# Options to curl
|
||||
curl_options="{{ patchman_client_curl_options }}"
|
||||
|
||||
# Comma or space delimited tags to send
|
||||
tags="{{ patchman_client_tags }}"
|
||||
|
||||
# Does the client output a report of the upload (e.g. for cronjob output)
|
||||
report=false
|
||||
|
||||
# Protocol version (1 = text, 2 = json)
|
||||
# Protocol 2 requires jq to be installed
|
||||
protocol={{ patchman_client_protocol }}
|
||||
|
||||
# API key for protocol 2 authentication
|
||||
{% if patchman_client_api_key %}
|
||||
api_key={{ patchman_client_api_key }}
|
||||
{% else %}
|
||||
#api_key=pm_your_api_key_here
|
||||
{% endif %}
|
||||
@@ -1,6 +0,0 @@
|
||||
# {{ ansible_managed }}
|
||||
# Send a daily package report to the Patchman server ({{ patchman_server_url }})
|
||||
SHELL=/bin/sh
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
{{ patchman_cron_minute }} {{ patchman_cron_hour }} * * * root /usr/sbin/patchman-client 2>&1 | logger -t patchman-client
|
||||
@@ -10,6 +10,7 @@
|
||||
- prometheus-node-exporter
|
||||
- nfs-common
|
||||
- qemu-guest-agent
|
||||
- net-tools
|
||||
update_cache: true
|
||||
|
||||
- name: Start guest qemu-guest-agent
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
- name: Reboot machine
|
||||
hosts: ["mqtt-server.ki5bhv.com", "git-server.ki5bhv.com", "webhost.ki5bhv.com", "clouflare.ki5bhv.com", "coding.ki5bhv.com",pi-hole-server.ki5bhv.com, "killer2.ki5bhv.com"]
|
||||
become: true
|
||||
|
||||
tasks:
|
||||
- name: Reboot machine
|
||||
ansible.builtin.reboot:
|
||||
reboot_timeout: 3600
|
||||
+80
-9
@@ -1,17 +1,88 @@
|
||||
---
|
||||
- name: Rebooting Machines Proxmox
|
||||
hosts: proxmox
|
||||
become: true
|
||||
# Reboot Ubuntu servers that have /run/reboot-required set, with a ntfy alert per server.
|
||||
# Order: pi-hole (DNS) first and alone, then the rest a few at a time, then this
|
||||
# Ansible controller last, so it never reboots out from under the run.
|
||||
# The hostnames for the DNS server and the controller are also in the play patterns below.
|
||||
|
||||
tasks:
|
||||
- name: Checking Reboot is needed
|
||||
- name: Find servers that need a reboot
|
||||
hosts: ubuntu_servers
|
||||
become: true
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Check for the reboot-required flag
|
||||
ansible.builtin.stat:
|
||||
path: /run/reboot-required
|
||||
register: reboot_required
|
||||
|
||||
- name: Reboot Machine
|
||||
become: true
|
||||
ansible.builtin.reboot:
|
||||
reboot_timeout: 3600
|
||||
- name: Group servers that need a reboot
|
||||
ansible.builtin.group_by:
|
||||
key: needs_reboot
|
||||
when: reboot_required.stat.exists
|
||||
|
||||
- name: Reboot servers
|
||||
hosts: needs_reboot:!ansible.ki5bhv.com
|
||||
become: true
|
||||
gather_facts: false
|
||||
vars:
|
||||
dns_server: pi-hole-server.ki5bhv.com
|
||||
ntfy_url: https://ntfy.ki5bhv.com/server
|
||||
tasks:
|
||||
- name: Reboot and notify
|
||||
block:
|
||||
# Runs on its own before anything else, so the other servers boot with DNS available.
|
||||
- name: Reboot DNS server first
|
||||
ansible.builtin.reboot:
|
||||
reboot_timeout: 1800
|
||||
when: inventory_hostname == dns_server
|
||||
|
||||
- name: Reboot remaining servers
|
||||
ansible.builtin.reboot:
|
||||
reboot_timeout: 1800
|
||||
when: inventory_hostname != dns_server
|
||||
throttle: 1 # one at a time: parallel boots overload the Proxmox host and services time out
|
||||
|
||||
- name: Notify reboot succeeded
|
||||
ansible.builtin.uri:
|
||||
url: "{{ ntfy_url }}"
|
||||
method: POST
|
||||
body: "{{ inventory_hostname }} needed a reboot and was rebooted"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
|
||||
rescue:
|
||||
- name: Notify reboot failed
|
||||
ansible.builtin.uri:
|
||||
url: "{{ ntfy_url }}"
|
||||
method: POST
|
||||
body: "{{ inventory_hostname }} needed a reboot but it FAILED - check reboot.log"
|
||||
headers:
|
||||
Priority: high
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
|
||||
- name: Mark host as failed
|
||||
ansible.builtin.fail:
|
||||
msg: "Reboot of {{ inventory_hostname }} failed"
|
||||
|
||||
- name: Reboot this Ansible controller last
|
||||
hosts: needs_reboot:&ansible.ki5bhv.com
|
||||
become: true
|
||||
gather_facts: false
|
||||
vars:
|
||||
ntfy_url: https://ntfy.ki5bhv.com/server
|
||||
tasks:
|
||||
# Sent first: once the reboot happens, nothing is left to report back.
|
||||
- name: Notify controller reboot
|
||||
ansible.builtin.uri:
|
||||
url: "{{ ntfy_url }}"
|
||||
method: POST
|
||||
body: "{{ inventory_hostname }} (Ansible controller) needed a reboot and is rebooting in 1 minute"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
|
||||
# The reboot module can't wait for the machine it is running on, so schedule it
|
||||
# a minute out and let this run finish and write its log first.
|
||||
- name: Schedule reboot in 1 minute
|
||||
ansible.builtin.command:
|
||||
argv: [shutdown, -r, "+1", "Ansible - reboot required"]
|
||||
changed_when: true
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
# Remove the PatchMon agent (server patch.ki5bhv.com / 192.168.1.8 was retired).
|
||||
- name: Remove PatchMon agent
|
||||
hosts: linux
|
||||
become: true
|
||||
tasks:
|
||||
- name: Check for PatchMon unit
|
||||
ansible.builtin.stat:
|
||||
path: /etc/systemd/system/patchmon-agent.service
|
||||
register: patchmon_unit
|
||||
|
||||
- name: Stop and disable patchmon-agent
|
||||
ansible.builtin.systemd_service:
|
||||
name: patchmon-agent
|
||||
state: stopped
|
||||
enabled: false
|
||||
when: patchmon_unit.stat.exists
|
||||
|
||||
- name: Find PatchMon cron entries
|
||||
ansible.builtin.find:
|
||||
paths: /etc/cron.d
|
||||
patterns: "patchmon*"
|
||||
register: patchmon_cron
|
||||
|
||||
- name: Remove PatchMon files
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop: "{{ ['/etc/systemd/system/patchmon-agent.service', '/usr/local/bin/patchmon-agent', '/etc/patchmon']
|
||||
+ (patchmon_cron.files | map(attribute='path') | list) }}"
|
||||
register: patchmon_removed
|
||||
|
||||
- name: Reload systemd
|
||||
ansible.builtin.systemd_service:
|
||||
daemon_reload: true
|
||||
when: patchmon_removed is changed
|
||||
@@ -0,0 +1,79 @@
|
||||
---
|
||||
# Upgrade Beszel: hub (docker compose on killer2) first, then agents on all ubuntu_servers.
|
||||
# Agents are the systemd binary at /opt/beszel-agent; uses the agent's built-in self-updater.
|
||||
|
||||
- name: Upgrade Beszel hub
|
||||
hosts: killer2.ki5bhv.com
|
||||
become: true
|
||||
tasks:
|
||||
- name: Pull and recreate beszel compose stack
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /home/justin/docker/beszel/
|
||||
pull: always
|
||||
recreate: auto
|
||||
register: hub
|
||||
retries: 3
|
||||
delay: 3
|
||||
until: hub is not failed
|
||||
|
||||
- name: Upgrade Beszel agents
|
||||
hosts: ubuntu_servers
|
||||
become: true
|
||||
vars:
|
||||
agent_bin: /opt/beszel-agent/beszel-agent
|
||||
tasks:
|
||||
- name: Check agent binary exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ agent_bin }}"
|
||||
register: agent_stat
|
||||
|
||||
- name: Skip hosts without the binary agent
|
||||
ansible.builtin.meta: end_host
|
||||
when: not agent_stat.stat.exists
|
||||
|
||||
- name: Get current version
|
||||
ansible.builtin.command: "{{ agent_bin }} -v"
|
||||
register: before
|
||||
changed_when: false
|
||||
|
||||
- name: Run self-update
|
||||
ansible.builtin.command: "{{ agent_bin }} update"
|
||||
register: update_out
|
||||
changed_when: false
|
||||
|
||||
- name: Get new version
|
||||
ansible.builtin.command: "{{ agent_bin }} -v"
|
||||
register: after
|
||||
changed_when: before.stdout != after.stdout
|
||||
|
||||
- name: Fix ownership
|
||||
ansible.builtin.file:
|
||||
path: /opt/beszel-agent
|
||||
owner: beszel
|
||||
group: beszel
|
||||
recurse: true
|
||||
|
||||
- name: Restart beszel-agent
|
||||
ansible.builtin.systemd:
|
||||
name: beszel-agent
|
||||
state: restarted
|
||||
when: before.stdout != after.stdout
|
||||
|
||||
# systemd reports success as soon as the process starts; make sure the new
|
||||
# version didn't crash right after.
|
||||
- name: Verify beszel-agent stayed running
|
||||
when: before.stdout != after.stdout
|
||||
block:
|
||||
- name: Give the agent time to start
|
||||
ansible.builtin.wait_for:
|
||||
timeout: 10
|
||||
|
||||
- name: Check beszel-agent is active
|
||||
ansible.builtin.command: systemctl is-active beszel-agent
|
||||
register: agent_active
|
||||
changed_when: false
|
||||
failed_when: agent_active.stdout != 'active'
|
||||
|
||||
- name: Report
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ before.stdout }} -> {{ after.stdout }}"
|
||||
+26
-56
@@ -1,72 +1,42 @@
|
||||
---
|
||||
- name: Proxmox Update and upgrade apt packages
|
||||
hosts: proxmox
|
||||
become: yes
|
||||
serial: 1
|
||||
- name: Update and upgrade apt packages
|
||||
hosts: proxmox:hardware
|
||||
become: true
|
||||
gather_subset: [min]
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Update packages with apt
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
lock_timeout: 600
|
||||
|
||||
- name: Installing proxmox guest agent
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
name: qemu-guest-agent
|
||||
state: latest
|
||||
|
||||
- name: Enable and restart proxmox agent
|
||||
handlers:
|
||||
- name: Restart qemu-guest-agent
|
||||
ansible.builtin.service:
|
||||
name: qemu-guest-agent
|
||||
state: restarted
|
||||
|
||||
- name: Upgrade packages with apt
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
upgrade: dist
|
||||
|
||||
- name: Clean up packages with apt
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
autoclean: true
|
||||
autoremove: true
|
||||
|
||||
- name: Hardware Update and upgrade apt packages
|
||||
hosts: hardware
|
||||
become: yes
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Update packages with apt
|
||||
- name: Apt maintenance
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
block:
|
||||
- name: Ensure qemu-guest-agent is installed
|
||||
when: inventory_hostname in groups['proxmox']
|
||||
ansible.builtin.apt:
|
||||
name: qemu-guest-agent
|
||||
state: present
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
lock_timeout: 600
|
||||
notify: Restart qemu-guest-agent
|
||||
|
||||
- name: Upgrade packages with apt
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
- name: Ensure qemu-guest-agent is running
|
||||
when: inventory_hostname in groups['proxmox']
|
||||
ansible.builtin.service:
|
||||
name: qemu-guest-agent
|
||||
state: started
|
||||
|
||||
- name: Upgrade packages and clean up
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
upgrade: dist
|
||||
|
||||
- name: Clean up packages with apt
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
autoclean: true
|
||||
autoremove: true
|
||||
|
||||
- name: installing net-tools on all
|
||||
hosts: all
|
||||
become: yes
|
||||
|
||||
tasks:
|
||||
- name: running apt
|
||||
when: ansible_facts['pkg_mgr'] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
name: net-tools
|
||||
state: latest
|
||||
|
||||
autoclean: true
|
||||
lock_timeout: 600
|
||||
# One host at a time, but an unreachable host no longer aborts the run like serial: 1 did
|
||||
throttle: 1
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
# Remove the PatchMon agent (server patch.ki5bhv.com / 192.168.1.8 was retired).
|
||||
- name: Remove PatchMon agent (Windows)
|
||||
hosts: windows
|
||||
tasks:
|
||||
- name: Stop and delete PatchMonAgent service
|
||||
ansible.windows.win_service:
|
||||
name: PatchMonAgent
|
||||
state: absent
|
||||
|
||||
- name: Remove PatchMon folders
|
||||
ansible.windows.win_file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- C:\Program Files\PatchMon
|
||||
- C:\ProgramData\PatchMon
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
# Upgrade the Beszel agent on Windows hosts.
|
||||
# Agent is installed with scoop (in the login user's profile) and run as an NSSM service "beszel-agent".
|
||||
# Service is stopped during the update because Windows locks the running exe.
|
||||
|
||||
- name: Upgrade Beszel agent (Windows)
|
||||
hosts: windows
|
||||
gather_facts: false
|
||||
vars:
|
||||
scoop: 'C:\Users\Justin\scoop\shims\scoop.ps1'
|
||||
agent_exe: 'C:\Users\Justin\scoop\shims\beszel-agent.exe'
|
||||
service: beszel-agent
|
||||
|
||||
tasks:
|
||||
- name: Get current version
|
||||
ansible.windows.win_command: '"{{ agent_exe }}" -v'
|
||||
register: before
|
||||
changed_when: false
|
||||
|
||||
- name: Update scoop buckets
|
||||
ansible.windows.win_shell: '& "{{ scoop }}" update'
|
||||
changed_when: false
|
||||
|
||||
- name: Check whether an update is available
|
||||
ansible.windows.win_shell: '& "{{ scoop }}" status 2>&1 | Out-String'
|
||||
register: status
|
||||
changed_when: false
|
||||
|
||||
- name: Update agent
|
||||
when: "'beszel-agent' in status.stdout"
|
||||
block:
|
||||
- name: Stop service
|
||||
ansible.windows.win_service:
|
||||
name: "{{ service }}"
|
||||
state: stopped
|
||||
|
||||
- name: Scoop update beszel-agent
|
||||
ansible.windows.win_shell: '& "{{ scoop }}" update beszel-agent 2>&1 | Out-String'
|
||||
register: upd
|
||||
|
||||
always:
|
||||
- name: Start service
|
||||
ansible.windows.win_service:
|
||||
name: "{{ service }}"
|
||||
state: started
|
||||
|
||||
- name: Get new version
|
||||
ansible.windows.win_command: '"{{ agent_exe }}" -v'
|
||||
register: after
|
||||
changed_when: before.stdout != after.stdout
|
||||
# scoop's exit code is lost through Out-String, so a failed update would otherwise
|
||||
# look like success. If an update was attempted, the version must have changed.
|
||||
failed_when: >-
|
||||
after.rc != 0 or
|
||||
(upd is not skipped and before.stdout | trim == after.stdout | trim)
|
||||
|
||||
- name: Report
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ before.stdout | trim }} -> {{ after.stdout | trim }}"
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
# Install Windows Updates on the [windows] inventory group and reboot if required.
|
||||
# Usage:
|
||||
# ansible-playbook windows/update.yaml # install + reboot if needed
|
||||
# ansible-playbook windows/update.yaml -e reboot=false # install only, report if reboot pending
|
||||
# ansible-playbook windows/update.yaml -e search_only=true # just list available updates
|
||||
|
||||
- name: Update Windows servers
|
||||
hosts: windows
|
||||
gather_facts: false
|
||||
vars:
|
||||
reboot: true
|
||||
search_only: false
|
||||
update_categories:
|
||||
- SecurityUpdates
|
||||
- CriticalUpdates
|
||||
- UpdateRollups
|
||||
- DefinitionUpdates
|
||||
- Updates
|
||||
|
||||
tasks:
|
||||
- name: Check connectivity
|
||||
ansible.windows.win_ping:
|
||||
|
||||
- name: Search for available updates
|
||||
ansible.windows.win_updates:
|
||||
category_names: "{{ update_categories }}"
|
||||
state: searched
|
||||
register: search
|
||||
when: search_only | bool
|
||||
|
||||
- name: List available updates
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ search.updates | dict2items | map(attribute='value.title') | list }}"
|
||||
when: search_only | bool
|
||||
|
||||
- name: Install updates and report
|
||||
when: not search_only | bool
|
||||
block:
|
||||
- name: Install updates
|
||||
ansible.windows.win_updates:
|
||||
category_names: "{{ update_categories }}"
|
||||
state: installed
|
||||
reboot: "{{ reboot | bool }}"
|
||||
reboot_timeout: 3600
|
||||
register: result
|
||||
# With reboot=false, updates blocked by the pending restart (WU_E_INSTALL_NOT_ALLOWED)
|
||||
# are expected; only fail on other errors.
|
||||
failed_when: >-
|
||||
result.failed_update_count | default(0) | int > 0 and
|
||||
(reboot | bool or
|
||||
result.updates | dict2items | map(attribute='value')
|
||||
| selectattr('failure_hresult_code', 'defined')
|
||||
| rejectattr('failure_hresult_code', 'equalto', 2149842966) | list | length > 0)
|
||||
|
||||
# Runs even if the install failed, so a failed run still shows what is pending.
|
||||
always:
|
||||
# Re-search afterwards: win_updates marks updates that were staged for a reboot as
|
||||
# "not installed" even after the reboot applies them, so this is the reliable view.
|
||||
- name: Check what is still pending
|
||||
ansible.windows.win_updates:
|
||||
category_names: "{{ update_categories }}"
|
||||
state: searched
|
||||
register: after
|
||||
|
||||
- name: Report
|
||||
vars:
|
||||
reboot_pending: "{{ after.reboot_required | default(result.reboot_required | default(false)) | bool }}"
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Processed this run: {{ result.updates | default({}) | dict2items | map(attribute='value.title') | list }}"
|
||||
- "Still pending: {{ after.updates | default({}) | dict2items | map(attribute='value.title') | list }}"
|
||||
- "Reboot still required: {{ reboot_pending }}{{ ' - reboot and re-run to finish' if reboot_pending | bool else '' }}"
|
||||
Reference in new issue
Block a user