commit 67953eb0a883c2ea5e5b11f38ad793198b00c62a Author: Caleb Fultz Date: Tue May 28 08:52:59 2024 -0400 initial 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