ansible gathering facts fails to retrieve ansible_distribution_release ("module invocation has junk after the json data")

Viewed 2085

running:

ansible -m setup <hostname>

(hostname being an ubuntu 20.04 desktop)

returns the warning:

[WARNING]: Module invocation had junk after the JSON data: AttributeError("module 'platform' has no attribute 'dist'")

and the output does not show any field "ansible_distribution_release".

As expected, tasks using this variable fail:

'ansible_distribution_release' is undefined

anything I may be missing ?

edit: the issue occurred with ansible 2.5.1, and was solved by running a newer version of ansible, see accepted answer.

1 Answers

I think you're running an older version of Ansible.

The use of platform.dist() in Ansible was removed in commit 61b1da, dated Dec. 10 2018. Python itself dropped support for platform.dist() in Python 3.8.

With Ansible 2.9.16, running the setup module against an Ubuntu 20.04 system yields:

$ ansible all -i 192.168.122.212, -u root -m setup | grep ansible_distribution
        "ansible_distribution": "Ubuntu",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/etc/os-release",
        "ansible_distribution_file_variety": "Debian",
        "ansible_distribution_major_version": "20",
        "ansible_distribution_release": "focal",
        "ansible_distribution_version": "20.04",
Related