{"id":392,"date":"2022-02-16T07:28:46","date_gmt":"2022-02-16T07:28:46","guid":{"rendered":"https:\/\/www.carmichaelclan.net\/?p=392"},"modified":"2022-03-19T09:54:58","modified_gmt":"2022-03-19T09:54:58","slug":"updated-ubuntu-dabian-update-ansible-script","status":"publish","type":"post","link":"https:\/\/www.carmichaelclan.net\/?p=392","title":{"rendered":"Updated Ubuntu\/Debian update ansible script"},"content":{"rendered":"\r\n<pre class=\"wp-block-code\"><code>---\r\n- hosts: all\r\n  gather_facts: yes\r\n  become: yes\r\n  serial: 1\r\n\r\n  tasks:\r\n    - name: Perform a dist-upgrade.\r\n      ansible.builtin.apt:\r\n        upgrade: dist\r\n        update_cache: yes\r\n\r\n    - name: Check if a reboot is required.\r\n      ansible.builtin.stat:\r\n        path: \/var\/run\/reboot-required\r\n        get_md5: no\r\n      register: reboot_required_file\r\n\r\n    - name: Reboot the server (if required).\r\n      ansible.builtin.reboot:\r\n      when: reboot_required_file.stat.exists == true\r\n\r\n    - name: Wait for Machine to come back online\r\n      local_action: wait_for\r\n             host={{ inventory_hostname }}\r\n                port=22\r\n                state=started\r\n                delay=65\r\n      when: reboot_required_file.stat.exists == true\r\n\r\n    - name: Remove dependencies that are no longer required.\r\n      ansible.builtin.apt:\r\n        autoremove: yes\r\n\r\n~                              <\/code><\/pre>\r\n\r\n\r\n\r\n<p>The above is an improvement on the previous version, thanks to Jeff Geerling. This version checks to see if a reboot is required then waits for the server to come back online.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>The above is an improvement on the previous version, thanks to Jeff Geerling. This version checks to see if a reboot is required then waits for the server to come back online.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-ansible"],"_links":{"self":[{"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=392"}],"version-history":[{"count":5,"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":413,"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=\/wp\/v2\/posts\/392\/revisions\/413"}],"wp:attachment":[{"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.carmichaelclan.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}