All Linux HowTo's Scripting HowTo's

Ansible To Get Linux OS Version Details

This article shows the Ansible playbook used to query target systems to get their version details. Ie, the details obtained from “/etc/*release”.

    - hosts: all
#      remote_user: root
#      become: yes

      - debug:
          - "ansible_distribution {{ hostvars[inventory_hostname].ansible_distribution }}"
          - "major version {{ hostvars[inventory_hostname].ansible_distribution_major_version }}"
          - "version {{ hostvars[inventory_hostname].ansible_distribution_version }}"

You might use the above playbook as demonstrated here – where “get-os-version.yaml” is the Ansible playbook above:

ansible-playbook get-os-version.yaml -i ./hosts

Notice in the above playbook there are two lines commented out. You’re not likely to need root access.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.