[clug] Ansible getting distribution

Chris Smart clug at csmart.io
Wed Jul 22 00:05:58 UTC 2020


On Wed, 22 Jul 2020, at 09:21, Bob Edwards via linux wrote:
> Thanks to those who replied.
> 
> Turns out that to get the "ansible_lsb" facts, you need the lsb-release
> package installed, which some Debian installs included, and others
> didn't, but all Ubuntu installs did.
> 
> I'll make sure it is installed in future... before running ansible...
> 

I don't think that you should need to use ansible_lsb facts in order to determine the distro, though... and therefore if so you don't need to worry about it being installed.

You should be able to get the distro and release info without it (like in my example) which I think probably comes from /etc/os-release, which is provided by base-files.

csmart at example-ubuntu-focal:~$ dpkg -S /etc/os-release 
base-files: /etc/os-release


If I look at my Focal test VM, I don't have lsb-release installed:

csmart at example-ubuntu-focal:~$ dpkg -l |grep lsb
ii  lsb-base                       11.1.0ubuntu2                         all          Linux Standard Base init script functionality

But the Ansible still works.

$ ansible-playbook -i inventory/ -l example-ubuntu-focal ./distro.yaml

PLAY [all] ************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************
ok: [example-ubuntu-focal]

TASK [Print out distro] ***********************************************************************************************
ok: [example-ubuntu-focal] => {
    "ansible_distribution": "Ubuntu"
}

TASK [Print out distro release] ***************************************************************************************
ok: [example-ubuntu-focal] => {
    "ansible_distribution_version": "20.04"
}

PLAY RECAP ************************************************************************************************************
example-ubuntu-focal       : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


-c



More information about the linux mailing list