Repository: ansible/ansible

Issue:
`ansible_os_family` variable no longer defined on OS X
##### ISSUE TYPE
- Bug Report
##### ANSIBLE VERSION

```
ansible 2.2.0 (devel 848b015ce6) last updated 2016/05/08 14:36:17 (GMT +800)
  lib/ansible/modules/core: (detached HEAD 1f5cf669dd) last updated 2016/05/07 12:18:20 (GMT +800)
  lib/ansible/modules/extras: (detached HEAD 431591c2b4) last updated 2016/05/07 12:18:20 (GMT +800)
  config file = /Users/pm5/src/ansible-playbooks/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

None.
##### OS / ENVIRONMENT

OS X El Capitan Version 10.11.4
##### SUMMARY

`ansible_os_family` is no longer defined in the `devel` branch.  I'm not sure if this variable is due to change (can't find any information of that), but there is still some [code](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts.py#L646) for that in the repository, so I guess I'll just report it.
##### STEPS TO REPRODUCE

```
ansible localhost -m setup | grep ansible_os_family
```
##### EXPECTED RESULTS

`ansible_os_family` used to be set to `Darwin` on OS X.
##### ACTUAL RESULTS

The variable is no longer defined.



Discussion:
1) Are the distribution_\* variables filled? What's the content?
2) Does 2.1 work correctly?

1) No, none of the `distribution_*` variables show up.  `ansible_distribution` and `ansible_distribution_version` are not defined.
2) Both `distribution_*` and `os_family` work as before in 2.1.

What is the output of `python -c "import platform; print(platform.system());"`?
Maybe you can run/debug the corresponding code yourself? I don't have a Mac system available here. If you don't have/want the full development setup you can just modify your installation and debug via setting additional variables like `facts['distribution_debug']`.

The codepath should be the elif at L674, and get_distribution_Darwin at L754. If `facts['distribution']` is set, the `os_family` gets set in the end of the `get_distribution_facts` function.

`python -c "import platform; print(platform.system());"` returns `Darwin`.

Judging from [L655](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts.py#L655), `get_distribution_facts` never gets run on OS X.  However if I add a clause in `populate` to run `get_distribution_facts`, Ansible complains about:

```
Using /Users/pm5/src/ansible-playbooks/ansible.cfg as config file
Loaded callback minimal of type stdout, v2.0
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: pm5
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1462779890.98-105696691161975 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1462779890.98-105696691161975 `" )'
<127.0.0.1> PUT /var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/tmpI5zlU4 TO /Users/pm5/.ansible/tmp/ansible-tmp-1462779890.98-105696691161975/setup
<127.0.0.1> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /Users/pm5/.pyenv/versions/2.7.10/bin/python /Users/pm5/.ansible/tmp/ansible-tmp-1462779890.98-105696691161975/setup; rm -rf "/Users/pm5/.ansible/tmp/ansible-tmp-1462779890.98-105696691161975/" > /dev/null 2>&1'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_module_setup.py", line 127, in <module>
    main()
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_module_setup.py", line 119, in main
    data = get_all_facts(module)
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py", line 3241, in get_all_facts
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py", line 3185, in ansible_facts
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py", line 182, in __init__
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py", line 658, in populate
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py", line 679, in get_distribution_facts
  File "/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py", line 757, in get_distribution_Darwin
AttributeError: 'Distribution' object has no attribute 'module'
localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_name": "setup"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_module_setup.py\", line 127, in <module>\n    main()\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_module_setup.py\", line 119, in main\n    data = get_all_facts(module)\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3241, in get_all_facts\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3185, in ansible_facts\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py\", line 182, in __init__\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py\", line 658, in populate\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py\", line 679, in get_distribution_facts\n  File \"/var/folders/sy/q12w5xyn4lngqxh_j63vwr4h0000gn/T/ansible_tCtpWD/ansible_modlib.zip/ansible/module_utils/facts.py\", line 757, in get_distribution_Darwin\nAttributeError: 'Distribution' object has no attribute 'module'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "parsed": false
}
```

So I ended up fixed it as in the pull request.


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
@@ -653,10 +653,7 @@ def __init__(self, module):
         self.module = module
 
     def populate(self):
-        if self.system == 'Linux':
-            self.get_distribution_facts()
-        elif self.system == 'Darwin':
-            self.get_distribution_facts()
+        self.get_distribution_facts()
         return self.facts
 
     def get_distribution_facts(self):
@@ -678,7 +675,7 @@ def get_distribution_facts(self):
             cleanedname = self.system.replace('-','')
             distfunc = getattr(self, 'get_distribution_'+cleanedname)
             distfunc()
-        else:
+        elif self.system == 'Linux':
             # try to find out which linux distribution this is
             dist = platform.dist()
             self.facts['distribution'] = dist[0].capitalize() or 'NA'


Test patch: