Repository: ansible/ansible

Issue:
One or more undefined variables: 'ansible_os_family' is undefined
Using `ansible-1.4.1` ...

``` bash
# ansible --version
ansible 1.4.1
```

... the play completes successfully

``` bash
# ansible-playbook -i /path/to/inventory --check -u root --ask-pass --ask-sudo-pass -l '~host-1[3-7]+\.example\.com' trunk/language_features/roletest.yml
SSH password: 
sudo password [defaults to SSH password]: 

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [host-16.example.com]
ok: [host-15.example.com]
ok: [host-13.example.com]
ok: [host-17.example.com]
ok: [host-14.example.com]

TASK: [shell echo "hi this is a pre_task step about {{inventory_hostname}}"] *** 
skipping: [host-16.example.com]
skipping: [host-17.example.com]
skipping: [host-15.example.com]
skipping: [host-13.example.com]
skipping: [host-14.example.com]

TASK: [foo | copy operation] ************************************************** 
ok: [host-16.example.com]
ok: [host-15.example.com]
ok: [host-17.example.com]
ok: [host-13.example.com]
ok: [host-14.example.com]

TASK: [foo | template operation] ********************************************** 
ok: [host-15.example.com]
ok: [host-16.example.com]
ok: [host-17.example.com]
ok: [host-13.example.com]
ok: [host-14.example.com]

TASK: [foo | demo that parameterized roles work] ****************************** 
skipping: [host-16.example.com]
skipping: [host-17.example.com]
skipping: [host-15.example.com]
skipping: [host-13.example.com]
skipping: [host-14.example.com]

TASK: [foo | copy operation] ************************************************** 
ok: [host-16.example.com]
ok: [host-17.example.com]
ok: [host-15.example.com]
ok: [host-14.example.com]
ok: [host-13.example.com]

TASK: [foo | template operation] ********************************************** 
ok: [host-16.example.com]
ok: [host-17.example.com]
ok: [host-15.example.com]
ok: [host-13.example.com]
ok: [host-14.example.com]

TASK: [foo | demo that parameterized roles work] ****************************** 
skipping: [host-17.example.com]
skipping: [host-16.example.com]
skipping: [host-15.example.com]
skipping: [host-13.example.com]
skipping: [host-14.example.com]

TASK: [shell echo 'this is a loose task'] ************************************* 
skipping: [host-16.example.com]
skipping: [host-17.example.com]
skipping: [host-15.example.com]
skipping: [host-13.example.com]
skipping: [host-14.example.com]

TASK: [shell echo 'this is a post_task about {{inventory_hostname}}'] ********* 
skipping: [host-16.example.com]
skipping: [host-17.example.com]
skipping: [host-15.example.com]
skipping: [host-13.example.com]
skipping: [host-14.example.com]

PLAY RECAP ******************************************************************** 
host-13.example.com        : ok=5    changed=0    unreachable=0    failed=0   
host-14.example.com        : ok=5    changed=0    unreachable=0    failed=0   
host-15.example.com        : ok=5    changed=0    unreachable=0    failed=0   
host-16.example.com        : ok=5    changed=0    unreachable=0    failed=0   
host-17.example.com        : ok=5    changed=0    unreachable=0    failed=0   
```

When upgrading to the latest `ansible-1.5` development stream ...

``` bash
# ansible --version
ansible 1.5
```

The same play fails ...

``` bash
# ansible-playbook -i /path/to/inventory --check -u root --ask-pass --ask-sudo-pass -l '~host-1[3-7]+\.example\.com' trunk/language_features/roletest.yml
SSH password: 
sudo password [defaults to SSH password]: 

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [host-16.example.com]
ok: [host-17.example.com]
ok: [host-15.example.com]
ok: [host-13.example.com]
ok: [host-14.example.com]

TASK: [shell echo "hi this is a pre_task step about {{inventory_hostname}}"] *** 
skipping: [host-16.example.com]
skipping: [host-17.example.com]
skipping: [host-15.example.com]
skipping: [host-13.example.com]
skipping: [host-14.example.com]

TASK: [foo | copy operation] ************************************************** 
ok: [host-16.example.com]
ok: [host-15.example.com]
ok: [host-17.example.com]
ok: [host-14.example.com]
ok: [host-13.example.com]

TASK: [foo | template operation] ********************************************** 
fatal: [host-16.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-15.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-14.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-17.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-13.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-16.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-15.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-14.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-17.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}
fatal: [host-13.example.com] => {'msg': "One or more undefined variables: 'ansible_os_family' is undefined", 'failed': True}

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/var/lib/awx/roletest.retry

host-13.example.com        : ok=2    changed=0    unreachable=1    failed=0   
host-14.example.com        : ok=2    changed=0    unreachable=1    failed=0   
host-15.example.com        : ok=2    changed=0    unreachable=1    failed=0   
host-16.example.com        : ok=2    changed=0    unreachable=1    failed=0   
host-17.example.com        : ok=2    changed=0    unreachable=1    failed=0   
```



Discussion:
To clarify from what I found by testing, this only happens when using the `--check` argument.  Without `--check` things work as expected.


Resolving patch:
diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py
--- a/lib/ansible/module_common.py
+++ b/lib/ansible/module_common.py
@@ -84,7 +84,7 @@ def _find_snippet_imports(self, module_data, module_path):
         module_style = 'old'
         if REPLACER in module_data:
             module_style = 'new'
-        elif 'from ansible.snippets.' in module_data:
+        elif 'from ansible.module_utils.' in module_data:
             module_style = 'new'
         elif 'WANT_JSON' in module_data:
             module_style = 'non_native_want_json'


Test patch: