# Error: winrm or requests is not installed: No module named 'winrm' (Packer ansible)

## TL;DR
The machine running Ansible (your build host or provisioner environment) lacks `pywinrm`. Install it (`pip install pywinrm`) where Ansible runs, then rebuild.

## The error

```
qemu: fatal: [the loopback address]: FAILED! => {"msg": "winrm or requests is not installed: No module named 'winrm'"}
Build 'qemu' errored after 8 minutes 43 seconds: Script exited with non-zero exit status: 2. Allowed exit codes are: [0]
```

## Fix it

1. Install pywinrm where Ansible executes: `pip install pywinrm` (add `requests` too if missing).
   - Success check: `python -c "import winrm"` succeeds.
2. If Ansible runs on the Packer host, install it on the host. If it runs on the guest via ansible-local, install it in the guest provisioning steps before the playbook.
   - Success check: the right Python environment has the module.
3. Re-run `packer build`.
   - Success check: `Gathering Facts` passes over WinRM.

## When to use this
You hit this with the Ansible provisioner targeting Windows guests over WinRM.

## When NOT to use this
Do not use this for SSH-based ansible failures on Linux guests (different transport, different modules).

## Compatibility
Packer 1.x, ansible provisioner, Windows guests, WinRM connection.

## Variants
- `No module named 'requests'` alongside (install `requests` too)
- The same error when `ansible_winrm_*` variables are set but pywinrm is absent

## Root cause
Ansible's WinRM connection plugin imports `winrm` at task time. A bare `pip install ansible` does not pull `pywinrm` (it is an optional dependency), so the first Windows task fails.

## Edge cases
- Newer ansible-core versions need `pywinrm>=0.4`; pin it if your distro ships an ancient one.
- Kerberos WinRM auth needs `pywinrm[kerberos]` plus system krb5 libs. That is a separate install.
