[clug] Ansible getting distribution

Bob Edwards bob at cs.anu.edu.au
Wed Jul 22 02:05:18 UTC 2020


On 22/7/20 10:05 am, Chris Smart via linux wrote:
> 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.
> 

Thanks for your help, Chris.

I applied your distro.yaml (thanks!) and this is what I got:

TASK [Print out distro] 
***************************************************************************************************************************
ok: [csittest.anu.edu.au] => { 

     "ansible_distribution": "Ubuntu" 

} 

ok: [wallaman.anu.edu.au] => { 

     "ansible_distribution": "Debian" 

} 

ok: [focaltmp1.vdi-dev] => { 

     "ansible_distribution": "VARIABLE IS NOT DEFINED!" 

} 

ok: [focaltmp3.vdi-dev] => { 

     "ansible_distribution": "VARIABLE IS NOT DEFINED!"
}
ok: [csitnode53.anu.edu.au] => {
     "ansible_distribution": "Debian"
}

TASK [Print out distro release] 
*******************************************************************************************************************
ok: [csittest.anu.edu.au] => {
     "ansible_distribution_version": "20.04"
}
ok: [wallaman.anu.edu.au] => {
     "ansible_distribution_version": "10.4"
}
ok: [focaltmp1.vdi-dev] => {
     "ansible_distribution_version": "VARIABLE IS NOT DEFINED!"
}
ok: [focaltmp3.vdi-dev] => {
     "ansible_distribution_version": "VARIABLE IS NOT DEFINED!"
}
ok: [csitnode53.anu.edu.au] => {
     "ansible_distribution_version": "10.3"
}

When I connect to focaltmp1 I can see:
ansible at focaltmp1:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
ansible at focaltmp1:~$ ls -las /etc/os-release
0 lrwxrwxrwx 1 root root 21 Apr 15 21:09 /etc/os-release -> 
../usr/lib/os-release
ansible at focaltmp1:~$ ls -las /usr/lib/os-release
4 -rw-r--r-- 1 root root 378 Apr 15 21:09 /usr/lib/os-release
ansible at focaltmp1:~$

So, looks like "ansible_distribution" facts are likely not coming from
/etc/os-release...

I guess I should just roll up my sleeves and take a look at the source.
Although installing lsb-release fixes my immediate problem (and my
Ansible tasks were already using "ansible_lsb.id" etc. in multiple
places).

cheers,
Bob Edwards.



More information about the linux mailing list