{"id":5637,"date":"2024-02-15T11:32:00","date_gmt":"2024-02-15T17:32:00","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5637"},"modified":"2024-02-15T15:17:59","modified_gmt":"2024-02-15T21:17:59","slug":"ansible-playbook-to-detect-os-version","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/ansible-playbook-to-detect-os-version\/","title":{"rendered":"Ansible Playbook to Detect OS version"},"content":{"rendered":"\n<p>This playbook can be used to report the Linux Distribution, OS Family, Distribution Version, and Distribution Major Version.  This can be helpful for verifying all operating systems are up to date, or for working out what to use in other playbooks.<\/p>\n\n\n\n<p>You will need to already have an inventory file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Playbook yaml file<\/h2>\n\n\n\n<p>The playbook is very simple.  Copy and paste the following contents into a file named &#8220;os_info.yaml&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code lang=\"yaml\" class=\"language-yaml line-numbers\">---\n- hosts: all\n  gather_facts: yes\n  become: false\n  tasks:\n  - name: Distribution\n    debug: msg=\" distribution {{ ansible_distribution }} - os_family {{ ansible_os_family}} - distribution_version {{ansible_distribution_version}} - distribution_major_version {{ ansible_distribution_major_version }}\"\n<\/code><\/pre>\n\n\n\n<p>If we wanted to, we could break out each Ansible variable in its own debug line.  I prefer having them all on a single line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Running the Playbook<\/h2>\n\n\n\n<p>Run the playbook like any other playbook.  Change inventory.ini to your inventory file.  If your inventory file is encrypted, use the &#8211;ask-vault-pass option.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ansible-playbook -i inventory.ini os_info.yaml <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Results<\/h2>\n\n\n\n<p>Here are some example results.  <\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background has-small-font-size\"><code lang=\"bash\" class=\"language-bash\"> ---------------------\n&lt; TASK [Distribution] &gt;\n ---------------------\n        \\   ^__^\n         \\  (oo)\\_______\n            (__)\\       )\\\/\\\n                ||----w |\n                ||     ||\n\n\nok: [almalinux_server01] =&gt; {\n    \"msg\": \" distribution AlmaLinux - os_family RedHat - distribution_version 9.3 - distribution_major_version 9\"\n}\nok: [fedora_server01] =&gt; {\n    \"msg\": \" distribution Fedora - os_family RedHat - distribution_version 39 - distribution_major_version 39\"\n}\nok: [centos_server] =&gt; {\n    \"msg\": \" distribution CentOS - os_family RedHat - distribution_version 7.9 - distribution_major_version 7\"\n}\nok: [ubuntu_serevr01] =&gt; {\n    \"msg\": \" distribution Ubuntu - os_family Debian - distribution_version 20.04 - distribution_major_version 20\"\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This playbook can be used to report the Linux Distribution, OS Family, Distribution Version, and Distribution Major Version. This can be helpful for verifying all operating systems are up to date, or for working out what to use in other &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/ansible-playbook-to-detect-os-version\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1646,1647],"tags":[1193,244,7,387,1200,1422,762],"class_list":["post-5637","post","type-post","status-publish","format-standard","hentry","category-ansible","category-automation","tag-ansible","tag-automation","tag-linux-2","tag-os","tag-playbook","tag-variables","tag-version"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5637"}],"version-history":[{"count":15,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5637\/revisions"}],"predecessor-version":[{"id":5657,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5637\/revisions\/5657"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}