[clug] Ansible getting distribution
Chris Smart
clug at csmart.io
Tue Jul 21 23:02:37 UTC 2020
On Tue, 21 Jul 2020, at 21:51, Bob Edwards via linux wrote:
> Hi all,
>
> Am kinda enjoying my journey with Ansible so far - it is very similar to
> Saltstack in lots of ways, but also different...
>
> At the moment, I am trying to find a consistent way to get the
> distribution of an Ansible "remote" ("minion" in Saltstack-speak). I
> have gathered some "facts" on some remotes using:
> $ ansible -i inventory $machinename -m setup > $machinename.facts
>
> Then, when I go to find out the distribution (the "id": field is in
> "ansible_lsb": {}):
>
> cecsit at ansible:/tmp$ grep '"id":' *facts
> csitnode53.facts: "id": "8000.fe1ad6a31b29",
> csitnode53.facts: "id": "Debian",
> csittest.facts: "id": "Ubuntu",
> focaltmp1.facts: "id": "Ubuntu",
> focaltmp3.facts: "id": "Ubuntu",
>
> cecsit at ansible:/tmp$ grep '"ansible_distribution":' *facts
> csitnode53.facts: "ansible_distribution": "Debian",
> csittest.facts: "ansible_distribution": "Ubuntu",
> wallaman.facts: "ansible_distribution": "Debian",
>
> so, some report distribution in "ansible_distribution", others in
> "ansible_lsb.id" and some in both...
>
> Any clues as to why they are divergent? My DuckDuckGo foo is not helping
> me...
>
Hey Bob,
Hmm... I think they should all have ansible_facts['distribution'] (ansible_distribution) which is probably the one I'd use. From your example above did you find that focaltmp1 and focaltmp3 don't have it? I have spun up some CentOS, Debian and Ubuntu VMs and all seem to work for me (including Ubuntu Focal release).
$ cat distro.yaml
---
- hosts: all
gather_facts: yes
tasks:
- name: Print out distro
debug: var=ansible_distribution
- name: Print out distro release
debug: var=ansible_distribution_version
$ ansible-playbook -i inventory ./distro.yaml
PLAY [all] *************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************
ok: [example-centos-7]
ok: [example-debian-10]
ok: [example-ubuntu-eoan]
ok: [example-ubuntu-focal]
TASK [Print out distro] ************************************************************************************************
ok: [example-centos-7] => {
"ansible_distribution": "CentOS"
}
ok: [example-debian-10] => {
"ansible_distribution": "Debian"
}
ok: [example-ubuntu-eoan] => {
"ansible_distribution": "Ubuntu"
}
ok: [example-ubuntu-focal] => {
"ansible_distribution": "Ubuntu"
}
TASK [Print out distro release] ****************************************************************************************
ok: [example-centos-7] => {
"ansible_distribution_version": "7.6"
}
ok: [example-debian-10] => {
"ansible_distribution_version": "10"
}
ok: [example-ubuntu-eoan] => {
"ansible_distribution_version": "19.10"
}
ok: [example-ubuntu-focal] => {
"ansible_distribution_version": "20.04"
}
PLAY RECAP *************************************************************************************************************
example-centos-7 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
example-debian-10 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
example-ubuntu-eoan : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
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