this var needs gather_facts to be true or setup to be called with at least ‘min’ level of facts.
STEPHENs-iMac:ansible mahespth$ ansible-playbook ansible_python_version
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] *****************************************************************************************************************************************************************************************************************
TASK [Do we have ansible_python_version] *****************************************************************************************************************************************************************************************
ok: [localhost] => {
"ansible_python_version": "VARIABLE IS NOT DEFINED!"
}
TASK [gather some facts] *********************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [Do we have ansible_python_version] *****************************************************************************************************************************************************************************************
ok: [localhost] => {
"ansible_python_version": "3.6.5"
}
PLAY RECAP ***********************************************************************************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
STEPHENs-iMac:ansible mahespth$ cat ansible_python_version
---
- hosts: localhost
gather_facts: false
tasks:
- name: Do we have ansible_python_version
debug: var=ansible_python_version
- name: gather some facts
setup:
gather_subset: min
- name: Do we have ansible_python_version
debug: var=ansible_python_version