FreeKB - ansible_distribution_version variable
Ansible - ansible_distribution_version variable

The ansible_distribution_major_version variable will return the version of your Ansible server. For example, let's say you have the following playbook.

---
- hosts: all
  tasks:
    - debug:
        msg: "Version is {{ ansible_distribution_version }}"

 

Running this playbook should return the following.

PLAY [all]

TASK [Gathering Facts]
ok: [server1.example.com]

TASK [debug]
ok: [server1.example.com] => {
    "msg: "Version is 7.10"
}

PLAY RECAP
server1.example.com : ok=2  changed=0  unreacable=0  failed=0

 

You could also use hostvars to return the distribution of the target server. For example, let's say you have the following playbook.

---
- hosts: all
  tasks:
    - debug:
        msg: "{{ inventory_hostname }} version is {{ hostvars[inventory_hostname].ansible_distribution_version }}"

 

Running this playbook should return the following.

PLAY [all]

TASK [Gathering Facts]
ok: [server1.example.com]

TASK [debug]
ok: [server1.example.com] => {
    "msg: "server1.example.com version is 6.10"
}

PLAY RECAP
server1.example.com : ok=2  changed=0  unreacable=0  failed=0

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter a007f in the box below so that we can be sure you are a human.




Comments