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.


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
@@ -179,7 +179,7 @@ def __init__(self, module, load_on_init=True):
         # about those first.
         if load_on_init:
             self.get_platform_facts()
-            self.facts.update(Distribution().populate())
+            self.facts.update(Distribution(module).populate())
             self.get_cmdline()
             self.get_public_ssh_host_keys()
             self.get_selinux_facts()
@@ -647,17 +647,19 @@ class Distribution(object):
         FreeBSD = 'FreeBSD', HPUX = 'HP-UX', openSUSE_Leap = 'Suse'
     )
 
-    def __init__(self):
+    def __init__(self, module):
         self.system = platform.system()
         self.facts = {}
+        self.module = module
 
     def populate(self):
         if self.system == 'Linux':
             self.get_distribution_facts()
+        elif self.system == 'Darwin':
+            self.get_distribution_facts()
         return self.facts
 
     def get_distribution_facts(self):
-
         # The platform module provides information about the running
         # system/distribution. Use this as a baseline and fix buggy systems
         # afterwards


Test patch: