Repository: ansible/ansible

Issue:
Incorrect distribution fact initialization on FreeBSD
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### ANSIBLE VERSION

```
ansible 2.2.0 (detached HEAD ae09648068) last updated 2016/05/13 00:14:41 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 9dfed7c849) last updated 2016/05/12 23:56:16 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 2665acb257) last updated 2016/05/12 23:56:16 (GMT +200)
  config file = /users/thomas/projects/ansible-multi-interp-test/ansible.cfg
  configured module search path = ['/users/thomas/projects/ansible/lib/ansible/modules/core']
```
##### CONFIGURATION

N/A
##### OS / ENVIRONMENT

FreeBSD 10.1-RELEASE-p5
##### SUMMARY

All playbooks fail during facts initialization.
##### STEPS TO REPRODUCE

Considering the following playbook "bug.yml"

```

---
- hosts: localhost
  tasks:
  - name: ping00
    action: ping

```
##### EXPECTED RESULTS

```
$ ansible-playbook bug.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [ping00] ******************************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0
```
##### ACTUAL RESULTS

Execution fails with:

```
$ ansible-playbook bug.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'distribution'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_JOq6Vd/ansible_module_setup.py\", line 127, in <module>\n    main()\n  File \"/tmp/ansible_JOq6Vd/ansible_module_setup.py\", line 119, in main\n    data = get_all_facts(module)\n  File \"/tmp/ansible_JOq6Vd/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3239, in get_all_facts\n  File \"/tmp/ansible_JOq6Vd/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3183, in ansible_facts\n  File \"/tmp/ansible_JOq6Vd/ansible_modlib.zip/ansible/module_utils/facts.py\", line 182, in __init__\n  File \"/tmp/ansible_JOq6Vd/ansible_modlib.zip/ansible/module_utils/facts.py\", line 656, in populate\n  File \"/tmp/ansible_JOq6Vd/ansible_modlib.zip/ansible/module_utils/facts.py\", line 735, in get_distribution_facts\nKeyError: 'distribution'\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @bug.retry

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   

```



Discussion:

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
@@ -660,6 +660,7 @@ 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
+        self.facts['distribution'] = self.system
         self.facts['distribution_release'] = platform.release()
         self.facts['distribution_version'] = platform.version()
 


Test patch: