How to use ansible to detect the specific flavor of Linux?

https://unix.stackexchange.com/questions/720614/how-to-use-ansible-to-detect-the-specific-flavor-of-linux

Asked 3 years, 3 months ago Modified 2 years, 6 months ago Viewed 3k times 0

How can I use ansible to detect the specific flavor of Linux, e.g. “Lubuntu” – a variant of Ubuntu?

On a Lubuntu 22.04, I tried to track ansible_distribution with the following playbook:


  • hosts: all gather_facts: yes become: false tasks:
    • name: Distribution debug: msg=”{{ ansible_distribution }}”
    • name: Distribution version debug: msg=”{{ ansible_distribution_version}}”
    • name: Distribution major version debug: msg=”{{ ansible_distribution_major_version }}” But I got Ubuntu as the ansible_distribution, which isn’t specific enough (for the task I have):

TASK [Distribution] ******************** ok: [127.0.0.1] => { “msg”: “Ubuntu” } … In general, how can one get the name of the specific Linux flavor such as Lubuntu?

– Additional Info –

On the Lubuntu, I have:

$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION=”Ubuntu 22.04.1 LTS”

$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy ubuntuansible Share Improve this question Follow edited Oct 12, 2022 at 8:40 asked Oct 12, 2022 at 1:14 tinlyx’s user avatar tinlyx 1,08833 gold badges1818 silver badges3333 bronze badges What is the content of /etc/lsb-release ? – Vladimir Botka CommentedOct 12, 2022 at 1:25 @VladimirBotka Please see the update I just added. – tinlyx CommentedOct 12, 2022 at 1:58 3 Forgetting Ansible for a moment; how would you identify a Lubuntu system vs. a generic Ubuntu system? – larsks CommentedOct 12, 2022 at 2:34 Depending on the target system you may need to construct the information from values gathered on the Remote Node like in Getting full name of the OS using Ansible facts. – U880D CommentedOct 12, 2022 at 7:00 Add a comment 2 Answers Sorted by:

Highest score (default) 1

There is no standard for recognising Ubuntu flavors. You can search for the configuration. See Is it possible to know which recognised flavor I am running using terminal?. For example,

shell> cat /var/log/installer/media-info Xubuntu 20.04 LTS “Focal Fossa” - Release amd64 (20200423) Ansible doesn’t gather facts about Ubuntu flavors. You’ll have to find out on your own. For example,

  • hosts: localhost

    vars:

    my_flavor: “{{ media_info.stdout.split() first }}”

    tasks:

    • command: cat /var/log/installer/media-info register: media_info
    • debug: var: my_flavor gives

    my_flavor: Xubuntu Share Improve this answer Follow answered Oct 12, 2022 at 5:42 Vladimir Botka’s user avatar Vladimir Botka 2,3881212 silver badges1414 bronze badges Add a comment 1

You can use ansible_distribution_release

You can easily see available facts on your host by running:

ansible all -m setup -a “filter=ansible_distribution*”

“ansible_facts”: { “ansible_distribution”: “Ubuntu”, “ansible_distribution_file_parsed”: true, “ansible_distribution_file_path”: “/etc/os-release”, “ansible_distribution_file_variety”: “Debian”, “ansible_distribution_major_version”: “22”, “ansible_distribution_release”: “jammy”, “ansible_distribution_version”: “22.04”, “discovered_interpreter_python”: “/usr/bin/python3” }, Share Improve this answer Follow answered Jul 12, 2023 at 21:30 BoomShadow’s user avatar BoomShadow 1,03411 gold badge1010 silver badges99 bronze badges This shows the release name, not the flavour. – Chris Down CommentedJul 12, 2023 at 21:34

Updated: