Repository: ansible/ansible

Issue:
ansible_distribution section of setup module includes NAME=\ and chops off anything after space
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
- setup module

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
  config file = /home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg
  configured module search path = [u'/home/szollinx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->
ANSIBLE_SSH_PIPELINING(/home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg) = True
DEFAULT_FORKS(/home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg) = 50
DEFAULT_HOST_LIST(/home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg) = [u'/home/szollinx/git/otc_infrastructure_ansible-configs/hosts']
DEFAULT_SCP_IF_SSH(/home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg) = True
RETRY_FILES_ENABLED(/home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg) = True
RETRY_FILES_SAVE_PATH(/home/szollinx/git/otc_infrastructure_ansible-configs/ansible.cfg) = /home/szollinx/git/otc_infrastructure_ansible-configs

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu 16.04.3 LTS

##### SUMMARY
<!--- Explain the problem briefly -->
When running ansible -m setup <fqdn> against a host running Clear Linux, the output for ansible_distribution is coming out as follows:

        "ansible_distribution": "NAME=\"Clear",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/usr/lib/os-release",
        "ansible_distribution_file_variety": "ClearLinux",
        "ansible_distribution_major_version": "18250",
        "ansible_distribution_release": "clear-linux-os",
        "ansible_distribution_version": "18250",

I also tried it with Python3 and it comes out even weirder as the ansible_distribution subsets are affected.

        "ansible_distribution": "NAME=\"Clear",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/usr/lib/os-release",
        "ansible_distribution_file_variety": "ClearLinux",
        "ansible_distribution_major_version": "NA",
        "ansible_distribution_release": "NA",
        "ansible_distribution_version": "NA",

I spoke to someone on the Clear Linux development team and they are saying this is an Ansible issue. Could someone investigate what is going on?

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ansible -m setup fqdn.of.host
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
        "ansible_distribution": "Clear Linux OS for Intel Architecture",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/usr/lib/os-release",
        "ansible_distribution_file_variety": "ClearLinux",
        "ansible_distribution_major_version": "18250",
        "ansible_distribution_release": "clear-linux-os",
        "ansible_distribution_version": "18250",
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
        "ansible_distribution": "NAME=\"Clear",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/usr/lib/os-release",
        "ansible_distribution_file_variety": "ClearLinux",
        "ansible_distribution_major_version": "18250",
        "ansible_distribution_release": "clear-linux-os",
        "ansible_distribution_version": "18250",
```



Discussion:
cc @alikins 
Small update. Ran the command on a newer version of Clear Linux and I am getting the same results. Version came out today. Version number is 18330.
@jborean93 & @alikins, ANy updates you can provide?
I'm going to close this for inactivity. I will try to find help elsewhere.
Could this be retested with with devel branch or a 2.4.1 release or release candidate? This could potentially be related to the same issues as other ansible_distribution bugs.
@szollinx 

Also, if anyone has an example /usr/lib/os-release from ClearLinux, post it. 

Even better would be output from 'hacking/tests/gen_distribution_version_testcase.py' ran on a ClearLinux system that shows this error.
@alikins 

I ran hacking/tests/gen_distribution_version_testcase.py on a ClearLinux server. Below is the output.

```
root@otctest-clearlinux ~ # ./gen_distribution_version_testcase.py
 [WARNING]: Host file not found: /etc/ansible/hosts
 [WARNING]: provided hosts list is empty, only localhost is available
{
    "platform.dist": [
        "Clear Linux OS for Intel Architecture",
        "18450",
        "clear-linux-os"
    ],
    "input": {},
    "name": "ClearLinux NA",
    "result": {
        "distribution_release": "NA",
        "distribution": "ClearLinux",
        "distribution_major_version": "NA",
        "os_family": "ClearLinux",
        "distribution_version": "NA"
    }
}
```

I also created a symlink from /usr/lib/os-release to /etc/os-release. I got different output.
```
root@otctest-clearlinux ~ # ./gen_distribution_version_testcase.py
 [WARNING]: Host file not found: /etc/ansible/hosts
 [WARNING]: provided hosts list is empty, only localhost is available
{
    "platform.dist": [
        "Clear Linux OS for Intel Architecture",
        "18450",
        "clear-linux-os"
    ],
    "input": {
        "/etc/os-release": "NAME=\"Clear Linux OS for Intel Architecture\"\nVERSION=1\nID=clear-linux-os\nVERSION_ID=18450\nPRETTY_NAME=\"Clear Linux OS for Intel Architecture\"\nANSI_COLOR=\"1;35\"\nHOME_URL=\"https://clearlinux.org\"\nSUPPORT_URL=\"https://clearlinux.org\"\nBUG_REPORT_URL=\"mailto:dev@lists.clearlinux.org\"\nPRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n"
    },
    "name": "Clear Linux OS for Intel Architecture 1",
    "result": {
        "distribution_release": "NA",
        "distribution": "Clear Linux OS for Intel Architecture",
        "distribution_major_version": "NA",
        "os_family": "Clear Linux OS for Intel Architecture",
        "distribution_version": "1"
    }
}
```

I also grabbed the output of the /usr/lib/os-release file for you.

```
root@otctest-clearlinux ~ # cat /usr/lib/os-release
NAME="Clear Linux OS for Intel Architecture"
VERSION=1
ID=clear-linux-os
VERSION_ID=18450
PRETTY_NAME="Clear Linux OS for Intel Architecture"
ANSI_COLOR="1;35"
HOME_URL="https://clearlinux.org"
SUPPORT_URL="https://clearlinux.org"
BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"
PRIVACY_POLICY_URL="http://www.intel.com/privacy"
```
@szollinx Excellent. Thanks!
@szollinx 

> I also created a symlink from /usr/lib/os-release to /etc/os-release. I got different output.

Ah, looks like gen_distribution_version_testcase.py  doesn't know about /usr/lib/os-release so it missed it. I'll update that when I fix this issue.

Resolving patch:
diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py
--- a/lib/ansible/module_utils/facts/system/distribution.py
+++ b/lib/ansible/module_utils/facts/system/distribution.py
@@ -82,7 +82,7 @@ class DistributionFiles:
         'OracleLinux': 'Oracle Linux',
         'RedHat': 'Red Hat',
         'Altlinux': 'ALT Linux',
-        'ClearLinux': 'Clear Linux Software for Intel Architecture',
+        'ClearLinux': 'Clear Linux',
         'SMGL': 'Source Mage GNU/Linux',
     }
 
@@ -115,6 +115,7 @@ def _parse_dist_file(self, name, dist_file_content, path, collected_facts):
             if self.SEARCH_STRING[name] in dist_file_content:
                 # this sets distribution=RedHat if 'Red Hat' shows up in data
                 dist_file_dict['distribution'] = name
+                dist_file_dict['distribution_file_search_string'] = self.SEARCH_STRING[name]
             else:
                 # this sets distribution to what's in the data, e.g. CentOS, Scientific, ...
                 dist_file_dict['distribution'] = dist_file_content.split()[0]


Test patch:
diff --git a/hacking/tests/gen_distribution_version_testcase.py b/hacking/tests/gen_distribution_version_testcase.py
--- a/hacking/tests/gen_distribution_version_testcase.py
+++ b/hacking/tests/gen_distribution_version_testcase.py
@@ -32,6 +32,7 @@
     '/etc/altlinux-release',
     '/etc/os-release',
     '/etc/coreos/update.conf',
+    '/usr/lib/os-release',
 ]
 
 fcont = {}
diff --git a/test/units/module_utils/test_distribution_version.py b/test/units/module_utils/test_distribution_version.py
--- a/test/units/module_utils/test_distribution_version.py
+++ b/test/units/module_utils/test_distribution_version.py
@@ -839,6 +839,37 @@
         }
     },
 
+    # ClearLinux https://github.com/ansible/ansible/issues/31501#issuecomment-340861535
+    {
+        "platform.dist": [
+            "Clear Linux OS for Intel Architecture",
+            "18450",
+            "clear-linux-os"
+        ],
+        "input": {
+            "/usr/lib/os-release": '''
+NAME="Clear Linux OS for Intel Architecture"
+VERSION=1
+ID=clear-linux-os
+VERSION_ID=18450
+PRETTY_NAME="Clear Linux OS for Intel Architecture"
+ANSI_COLOR="1;35"
+HOME_URL="https://clearlinux.org"
+SUPPORT_URL="https://clearlinux.org"
+BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"
+PRIVACY_POLICY_URL="http://www.intel.com/privacy"
+'''
+        },
+        "name": "Clear Linux OS for Intel Architecture 1",
+        "result": {
+            "distribution_release": "clear-linux-os",
+            "distribution": "ClearLinux",
+            "distribution_major_version": "18450",
+            "os_family": "ClearLinux",
+            "distribution_version": "18450"
+        }
+    },
+
     # ArchLinux with no /etc/arch-release but with a /etc/os-release with NAME=Arch Linux
     # The fact needs to map 'Arch Linux' to 'Archlinux' for compat with 2.3 and earlier facts
     {