FreeKB - Ansible ansible_distribution_version magic variable
Ansible - ansible_distribution_version magic variable

The gather_facts module must be set to true, which is the default setting of the gather_facts module. In other words, the gather_facts module must not be set to false.

The ansible_distribution_major_version magic variable will return the version of your control node (that's 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.

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

 

You could also use the hostvars magic variable to return the distribution of the managed node (e.g. target system) 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.

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

 



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 48cd2 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |