1

I used gather_facts to get the OS details of each instance that I'm dealing with. For Amazon Linux OS, it just says Amazon 2 or Amazon 2018.

Use case: I'm dynamically constructing the file name for a task. The file name is nothing but the name of the OS. When I see the contents of /etc/os-release, it says Amazon Linux only but Ansible facts returns:

"ansible_facts": {
    "discovered_interpreter_python": "/usr/bin/python2.7",
    "distribution": "Amazon",
    "distribution_file_parsed": true,
    "distribution_file_path": "/etc/os-release",
    "distribution_file_variety": "Amazon",
    "distribution_major_version": "2",
    "distribution_minor_version": "NA",
    "distribution_release": "NA",
    "distribution_version": "2",
    "gather_subset": [
        "distribution",
        "!all",
        "!min"
    ],
    "module_setup": true,
    "os_family": "RedHat",
}

Is there a way to get the full name of the distribution? I personally feel Amazon 2 doesn't set the proper context.

U880D
  • 8,601
  • 6
  • 24
  • 40
Ehack2
  • 49
  • 2
  • 3
  • 1
    `I personally feel "Amazon 2" doesn't set the proper context.` <= meanwhile it is the appropriate context, as good as running this on my local machine returns it is a Debian os familly for which the distribution is Ubuntu version 20.04 if I read it from the exact same variables. What else exactly do you expect ? – Zeitounator Feb 08 '22 at 13:53
  • I expect the name to be returned as specified in os-release file. Example: NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" – Ehack2 Feb 08 '22 at 14:01
  • 1
    If you take a look at the Ansible [platforms](https://github.com/dmsimard/ansible-sandbox/tree/master/get-galaxy-platforms) you'll see that Ansible simply recognizes "any" version of "Amazon Linux 2". You'll also see that there are many versions of "Amazon" which is for whatever reason recognized as a different system. Open an issue with Ansible if you think this is wrong. This question should be closed. It's off-topic here. – Vladimir Botka Feb 08 '22 at 14:50
  • 1
    `{{ ansible_lsb.description }}` ? This reports "Ubuntu 20.04.3 LTS" on my system. – Zeitounator Feb 08 '22 at 15:13

1 Answers1

0

A RHEL system

cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)

will report as follow

    distribution: RedHat
    distribution_file_parsed: true
    distribution_file_path: /etc/redhat-release
    distribution_file_search_string: Red Hat
    distribution_file_variety: RedHat
    distribution_major_version: '7'
    distribution_release: Maipo
    distribution_version: '7.9'
    gather_subset:
    - distribution
    - '!all'
    - '!min'
    module_setup: true
    os_family: RedHat

I expect the name to be returned as specified in os-release file

Which could be than used for

"{{ distribution_file_search_string }} Linux {{ distribution_version }} ({{ distribution_release }})"

So it is almost the case. Furthermore you can have your own set_fact parts

- name: Set OS facts
  set_fact:
    NAME: "{{ distribution }} Linux" 
    VERSION: "{{ distribution_major_version }}" 
    VERSION_ID: "{{ distribution_version }}"
    PRETTY_NAME: "{{ distribution }} Linux {{ distribution_version }}"

- name: Set OS facts
  set_fact:
    ID: "amzn" 
    ID_LIKE: "centos rhel fedora"
  when:  (ansible_facts['distribution'] == "Amazon" and ansible_facts['distribution_major_version'] == "2")

with Conditionals.

If really necessary one could enhance or extend the module facts/system/distribution.py.

U880D
  • 8,601
  • 6
  • 24
  • 40