ansible-inventory-grapher on windows - installing ansible on Windows (revisit)

Hi,
I’m trying to allow ansible-inventory-grapher to install under pip on Windows. I’m using the standard python 2.7 for Windows.

As per https://github.com/ansible/ansible/issues/7049, the install fails during an import pwd.

I understand you don’t really want to support running Ansible itself on Windows, but it would be nice if it could at least be installed so that the library software could be used by other software.

The main problem is during any module import that relies on ansible.constants - and that’s only used for setting REMOTE_USER.

Something like

try:
import pwd
active_user = pwd.getpwuid(os.geteuid())[0]
except ImportError:
import getpass
active_user = getpass.getuser()

might suffice.

Anyway, happy to submit a PR after testing, if it’s at all likely to be accepted.

I can remove the dependency on ansible.constants in ansible-inventory-grapher (assuming a minor patch to remove the constant in the default to ansible.inventory.Inventory would be accepted) but that doesn’t help me during the installation process (as it’s ansible’s setup.py that is failing due to importing ansible.constants). And I really would prefer to use ansible’s inventory library rather than some copy that becomes out of date

Will

I think the larger issue is that, over time, this stuff is going to build up to the point where we’re not willing to commit to not using a lib that can’t run on Windows.

(For new readers on Google who are not Will, we do support managing Windows nodes, just not running from Windows, unless by which you mean a Linux VM running on Windows, which is preferred – don’t think we can’t manage Windows nodes, we do, see docs.ansible.com and search for Windows).

So I think yes, I think we’re totally ok with a function in utils wrapping pwd, as well as getpass.

Though in the future, I’m not sure if something MAY come up that we wish to rely on.

We’ll probably have to deal with that on a case by case basis as it arises.

This change was harder than I first thought, although nowhere near as bad as one rabbit hole I ended up down. I’m pretty pleased with the relative simplicity of the patch. It won’t solve all windows problems, but it does mean that ansible-inventory-grapher installs and runs using standard windows python modules (plus precompiled pycrypto binaries)

Pull request at
https://github.com/ansible/ansible/pull/9210

Will