Repository: ansible/ansible

Issue:
Could not find imported module support code for 'Ansible.ModuleUtils.PowerShellLegacy'
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
Windows support

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/test/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
Irrelevant

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu 16.04.2 (WSL) control machine to Windows Server 2016 with WMF 5.1
##### SUMMARY
<!--- Explain the problem briefly -->
Most modules that can be run on Windows fail in latest 2.4 `devel` branch: all `win_*` I tried and `setup` too.
However, `raw` does work.

Switching to ...ansible.git@stable-2.3 everything works again.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```sh
sudo -H pip install git+https://github.com/ansible/ansible.git@devel
ansible -i dev -m setup [windows_target]
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Successful task execution
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
windows-target | FAILED! => {
    "failed": true,
    "msg": "Could not find imported module support code for 'Ansible.ModuleUtils.PowerShellLegacy'."
}
```



Discussion:
I just ran into this too... Not sure what happened, but in my case, at least, when I did a pip install of a local development branch into a virtual environment, it did not copy over the PowerShell modules into my virtual environment's /lib/python2.7/site-packages/ansible/module_utils/powershell/ directory. I copied them over manually, and the error went away... I don't know why they were not copied automatically, but this may allow you to work around the issue if you are running into the same thing I did...
@nwchandler, thanks, that worked!
I can confirm that error is due to files missing in `module_utils/powershell/`
Thanks for the extra bit of data that it only broke on a pip install- looks like we need to update some of the paths on setup.py to get the Powershell modules (and including the subtrees).
@nitzmahone, I've submitted a PR for this one.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -172,9 +172,10 @@ def run(self):
     packages=find_packages('lib'),
     package_data={
         '': [
-            'module_utils/*.ps1',
-            'modules/windows/*.ps1',
+            'module_utils/powershell/*.psm1',
+            'module_utils/powershell/*/*.psm1',
             'modules/windows/*.ps1',
+            'modules/windows/*/*.ps1',
             'galaxy/data/*/*.*',
             'galaxy/data/*/*/.*',
             'galaxy/data/*/*/*.*',


Test patch: