{"id":506,"date":"2022-09-02T18:08:54","date_gmt":"2022-09-02T18:08:54","guid":{"rendered":"https:\/\/maboc.nl\/?p=506"},"modified":"2022-09-02T18:08:54","modified_gmt":"2022-09-02T18:08:54","slug":"ansible-reboot-after-updating-packages","status":"publish","type":"post","link":"https:\/\/maboc.nl\/?p=506","title":{"rendered":"ansible reboot after updating packages"},"content":{"rendered":"<p>When installing security\/kernel packages the system must be rebooted.<br \/>\nIt would be a bit silly to reboot always.<br \/>\nSo..without further ado&#8230;you can solve this for example with the following playbook:<\/p>\n<pre>\r\n[martijn@fedora basis]$ cat update_all.yaml \r\n---\r\n\r\n - name: Update alle hosts\r\n   hosts: all\r\n   become: true\r\n   tasks:\r\n     - name: install dnf tools\r\n       dnf: \r\n         state: present\r\n         name: dnf-utils\r\n\r\n     - name: update alle hosts \r\n       dnf:\r\n         state: latest\r\n         name: \"*\"\r\n\r\n     - name: restart...?\r\n       command: needs-restarting -r\r\n       register: result\r\n       ignore_errors: yes\r\n\r\n     - name: reboot\r\n       reboot:    \r\n       when: result.rc == 1\r\n[martijn@fedora basis]$\r\n<\/pre>\n<p>After updating all packages the playbook installs the packages dnf-utils. This package contains the handy command &#8220;needs-restarting&#8221;. If this commands return a 1 then the machine needs a restart. The result of needs-restarting is stored in the result variable. Later on you can restart if result.rc equals 1.<\/p>\n<p>Have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When installing security\/kernel packages the system must be rebooted. It would be a bit silly to reboot always. So..without further ado&#8230;you can solve this for example with the following playbook: [martijn@fedora basis]$ cat update_all.yaml &#8212; &#8211; name: Update alle hosts hosts: all become: true tasks: &#8211; name: install dnf tools dnf: state: present name: dnf-utils [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83,56],"tags":[84,85,58],"class_list":["post-506","post","type-post","status-publish","format-standard","hentry","category-ansible","category-linux","tag-ansible","tag-dnf","tag-linux"],"_links":{"self":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=506"}],"version-history":[{"count":4,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/506\/revisions"}],"predecessor-version":[{"id":510,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/506\/revisions\/510"}],"wp:attachment":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}