Repository: ansible/ansible

Issue:
wait_for missing import for os: "global name 'os' is not defined"
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
wait_for

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 416d9774ce) last updated 2017/06/09 10:50:57 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/tmp/ansible/lib/ansible
  executable location = /root/tmp/ansible/bin/ansible
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
N/A

##### SUMMARY

When running the wait_for task to check for the existence of a file that is present, ansible reports a module failure due to `global name 'os' is not defined`. 

##### STEPS TO REPRODUCE

```
cat << EOF > inventory
[local]
localhost ansible_connection=local
EOF

cat << EOF > playbook.yml
---
- hosts: local
  tasks:
  - wait_for:
      path: '/tmp/test_file'
      timeout: 1
EOF

touch /tmp/test_file

ansible -i inventory playbook.yml
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
`wait_for` successfully confirms file exists

##### ACTUAL RESULTS
```
Traceback (most recent call last):
  File "/tmp/ansible_SksI7U/ansible_module_wait_for.py", line 606, in <module>
    main()
  File "/tmp/ansible_SksI7U/ansible_module_wait_for.py", line 505, in main
    os.stat(path)
NameError: global name 'os' is not defined
fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_SksI7U/ansible_module_wait_for.py\", line 606, in <module>\n    main()\n  File \"/tmp/ansible_SksI7U/ansible_module_wait_for.py\", line 505, in main\n    os.stat(path)\nNameError: global name 'os' is not defined\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}
```

Full output:
https://gist.github.com/jladdjr/bd5506b56d3bb66d975de278eb61c207#file-gistfile1-txt-L114


Discussion:
[This commit](https://github.com/ansible/ansible/commit/6e98dbbfd74affa090c3e0c64a28674a38cf1382#diff-c15dffe3b5403056a55c6ca98b41e63cL601) removed the following import which indirectly imported `os`:
`from ansible.module_utils.basic import *`
ping @dagwieers
cc @gregswift
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/utilities/logic/wait_for.py b/lib/ansible/modules/utilities/logic/wait_for.py
--- a/lib/ansible/modules/utilities/logic/wait_for.py
+++ b/lib/ansible/modules/utilities/logic/wait_for.py
@@ -183,6 +183,7 @@
 
 from ansible.module_utils.basic import AnsibleModule, load_platform_subclass
 from ansible.module_utils._text import to_native
+from ansible.module_utils.pycompat24 import get_exception
 
 
 HAS_PSUTIL = False


Test patch: