From 67953eb0a883c2ea5e5b11f38ad793198b00c62a Mon Sep 17 00:00:00 2001 From: Caleb Fultz Date: Tue, 28 May 2024 08:52:59 -0400 Subject: [PATCH] initial --- README.md | 1 + hosts | 5 +++++ run.sh | 1 + update.yml | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 README.md create mode 100644 hosts create mode 100755 run.sh create mode 100644 update.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..bcf45ef --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# UpdateServersPlaybook diff --git a/hosts b/hosts new file mode 100644 index 0000000..fbdc054 --- /dev/null +++ b/hosts @@ -0,0 +1,5 @@ +[allservers] +ip1-here +ip2-here +ip3-here +ip4-here diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..4054c32 --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +/usr/bin/ansible-playbook -i hosts update.yml --ask-become-pass diff --git a/update.yml b/update.yml new file mode 100644 index 0000000..4f1b1c2 --- /dev/null +++ b/update.yml @@ -0,0 +1,32 @@ +--- +- name: update all remote hosts + hosts: allservers + + tasks: + - name: update Ubuntu apt cache + become: true + apt: + update_cache: yes + force_apt_get: yes + cache_valid_time: 3600 + + - name: update all apt packages + become: true + apt: + state: latest + force_apt_get: yes + + - name: check to see if reboot is needed + register: reboot_required_file + stat: path=/var/run/reboot-required get_checksum=false + + - name: Reboot the server + become: true + reboot: + msg: "Reboot initiated by Ansible due to kernel updates" + connect_timeout: 5 + reboot_timeout: 300 + pre_reboot_delay: 0 + post_reboot_delay: 30 + test_command: uptime + when: reboot_required_file.stat.exists \ No newline at end of file