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.
41 Answer
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. ... and if interested in more, like for unknown an os_family: NA, see Can't return os_family using ansible_os_family on VMware ESX.