Repository: ansible/ansible

Issue:
ansible_os_family = "NA" on Archlinux host (1.8-git)
##### Issue Type:

Bug report
##### Ansible Version:

$ ansible --version
ansible 1.8
##### Environment:

Archlinux host
##### Summary:

ansible_os_family no longer returns "Archlinux" for my Arch machines. It now returns "NA"
##### Steps To Reproduce:

ansible -m setup <any configured Arch hostname>|grep ansible_os_family
##### Expected Results:

```
    "ansible_os_family": "Archlinux", 
```
##### Actual Results:

```
    "ansible_os_family": "NA", 
```



Discussion:
Observing the same behaviour here in Ansible 1.7.1.

```
~$ ansible -m setup arch-box | grep ansible_os_family
        "ansible_os_family": "NA",  
```

Same here with 1.7.1. Also NA for the the ansible_distribution values:

```
    "ansible_os_family": "NA", 
    "ansible_distribution": "NA", 
    "ansible_distribution_major_version": "NA", 
    "ansible_distribution_release": "NA", 
    "ansible_distribution_version": "NA", 
```

Confirming the observations of @dcbishop using 1.7.1 on Arch Linux. All distribution and the os_family values are NA.

# Module Repo Information

Hi!

Thanks very much for your interest in Ansible.  It sincerely means a lot to us. 

This appears to be a submission about a module, and aside from action_plugins, if you know what those are, the modules
in ansible are now moved two seperate repos.  We would appreciate if you can submit this there instead.

If this is about a new module, submit pull requests or ideas to:
- https://github.com/ansible/ansible-modules-extras

If this is about an existing module:
- Find the module at http://docs.ansible.com/list_of_all_modules.html
- Open the documentation page for that module
- If the bottom of the docs say "This is an extras module", submit your ticket to https://github.com/ansible/ansible-modules-extras
- Otherwise, submit your module to https://github.com/ansible/ansible-modules-core

Additionally, should you need more help with this, you can ask questions on:
- IRC: #ansible on irc.freenode.net  
- mailing list: https://groups.google.com/forum/#!forum/ansible-project

Thanks!

Resubmitted: https://github.com/ansible/ansible-modules-core/issues/34`


Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -273,84 +273,85 @@ def get_distribution_facts(self):
             self.facts['distribution_release'] = dist[2] or 'NA'
             # Try to handle the exceptions now ...
             for (path, name) in Facts.OSDIST_LIST:
-                if os.path.exists(path) and os.path.getsize(path) > 0:
-                    if self.facts['distribution'] in ('Fedora', ):
-                        # Once we determine the value is one of these distros
-                        # we trust the values are always correct
-                        break
-                    elif name == 'RedHat':
-                        data = get_file_content(path)
-                        if 'Red Hat' in data:
-                            self.facts['distribution'] = name
-                        else:
-                            self.facts['distribution'] = data.split()[0]
-                        break
-                    elif name == 'OtherLinux':
-                        data = get_file_content(path)
-                        if 'Amazon' in data:
-                            self.facts['distribution'] = 'Amazon'
-                            self.facts['distribution_version'] = data.split()[-1]
-                            break
-                    elif name == 'OpenWrt':
-                        data = get_file_content(path)
-                        if 'OpenWrt' in data:
-                            self.facts['distribution'] = name
-                            version = re.search('DISTRIB_RELEASE="(.*)"', data)
-                            if version:
-                                self.facts['distribution_version'] = version.groups()[0]
-                            release = re.search('DISTRIB_CODENAME="(.*)"', data)
-                            if release:
-                                self.facts['distribution_release'] = release.groups()[0]
+                if os.path.exists(path):
+                    if os.path.getsize(path) > 0:
+                        if self.facts['distribution'] in ('Fedora', ):
+                            # Once we determine the value is one of these distros
+                            # we trust the values are always correct
                             break
-                    elif name == 'Alpine':
-                        data = get_file_content(path)
-                        self.facts['distribution'] = name
-                        self.facts['distribution_version'] = data
-                        break
-                    elif name == 'Solaris':
-                        data = get_file_content(path).split('\n')[0]
-                        if 'Solaris' in data:
-                            ora_prefix = ''
-                            if 'Oracle Solaris' in data:
-                                data = data.replace('Oracle ','')
-                                ora_prefix = 'Oracle '
-                            self.facts['distribution'] = data.split()[0]
-                            self.facts['distribution_version'] = data.split()[1]
-                            self.facts['distribution_release'] = ora_prefix + data
+                        elif name == 'RedHat':
+                            data = get_file_content(path)
+                            if 'Red Hat' in data:
+                                self.facts['distribution'] = name
+                            else:
+                                self.facts['distribution'] = data.split()[0]
                             break
-                    elif name == 'SuSE':
-                        data = get_file_content(path)
-                        if 'suse' in data.lower():
-                            if path == '/etc/os-release':
-                                release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
+                        elif name == 'OtherLinux':
+                            data = get_file_content(path)
+                            if 'Amazon' in data:
+                                self.facts['distribution'] = 'Amazon'
+                                self.facts['distribution_version'] = data.split()[-1]
+                                break
+                        elif name == 'OpenWrt':
+                            data = get_file_content(path)
+                            if 'OpenWrt' in data:
+                                self.facts['distribution'] = name
+                                version = re.search('DISTRIB_RELEASE="(.*)"', data)
+                                if version:
+                                    self.facts['distribution_version'] = version.groups()[0]
+                                release = re.search('DISTRIB_CODENAME="(.*)"', data)
                                 if release:
                                     self.facts['distribution_release'] = release.groups()[0]
-                                    break
-                            elif path == '/etc/SuSE-release':
-                                data = data.splitlines()
-                                for line in data:
-                                    release = re.search('CODENAME *= *([^\n]+)', line)
-                                    if release:
-                                        self.facts['distribution_release'] = release.groups()[0].strip()
-                                        break
-                    elif name == 'Debian':
-                        data = get_file_content(path)
-                        if 'Debian' in data:
-                            release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
-                            if release:
-                                self.facts['distribution_release'] = release.groups()[0]
-                            break
-                    elif name == 'Mandriva':
-                        data = get_file_content(path)
-                        if 'Mandriva' in data:
-                            version = re.search('DISTRIB_RELEASE="(.*)"', data)
-                            if version:
-                                self.facts['distribution_version'] = version.groups()[0]
-                            release = re.search('DISTRIB_CODENAME="(.*)"', data)
-                            if release:
-                                self.facts['distribution_release'] = release.groups()[0]
+                                break
+                        elif name == 'Alpine':
+                            data = get_file_content(path)
                             self.facts['distribution'] = name
+                            self.facts['distribution_version'] = data
                             break
+                        elif name == 'Solaris':
+                            data = get_file_content(path).split('\n')[0]
+                            if 'Solaris' in data:
+                                ora_prefix = ''
+                                if 'Oracle Solaris' in data:
+                                    data = data.replace('Oracle ','')
+                                    ora_prefix = 'Oracle '
+                                self.facts['distribution'] = data.split()[0]
+                                self.facts['distribution_version'] = data.split()[1]
+                                self.facts['distribution_release'] = ora_prefix + data
+                                break
+                        elif name == 'SuSE':
+                            data = get_file_content(path)
+                            if 'suse' in data.lower():
+                                if path == '/etc/os-release':
+                                    release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
+                                    if release:
+                                        self.facts['distribution_release'] = release.groups()[0]
+                                        break
+                                elif path == '/etc/SuSE-release':
+                                    data = data.splitlines()
+                                    for line in data:
+                                        release = re.search('CODENAME *= *([^\n]+)', line)
+                                        if release:
+                                            self.facts['distribution_release'] = release.groups()[0].strip()
+                                            break
+                        elif name == 'Debian':
+                            data = get_file_content(path)
+                            if 'Debian' in data:
+                                release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data)
+                                if release:
+                                    self.facts['distribution_release'] = release.groups()[0]
+                                break
+                        elif name == 'Mandriva':
+                            data = get_file_content(path)
+                            if 'Mandriva' in data:
+                                version = re.search('DISTRIB_RELEASE="(.*)"', data)
+                                if version:
+                                    self.facts['distribution_version'] = version.groups()[0]
+                                release = re.search('DISTRIB_CODENAME="(.*)"', data)
+                                if release:
+                                    self.facts['distribution_release'] = release.groups()[0]
+                                self.facts['distribution'] = name
+                                break
                     else:
                         self.facts['distribution'] = name
 


Test patch: