pyinfra
pyinfra copied to clipboard
Add best-effort Ansible module bridge operation
Summary
- add
ansible.module(...)that executes real Ansible modules on the target host (upload module + ansiblemodule_utils/_vendor, run with stdin JSON) - add optional extra
pyinfra[ansible]and includeansiblein test deps - update local E2E and examples to use
ansible.modulewithansible.builtin.ping - add SSH localhost E2E test (skipped by default via env gate)
- prefer
pyinfra.operations.*when resolving CLI operation names
How To Use
Python deploy:
ansible.module(src="examples/ansible_modules/ping.py", kwargs={"data": "pyinfra"})
CLI:
pyinfra -y -v @local ansible.module examples/ansible_modules/ping.py data=pyinfra
Ansible Module Included
examples/ansible_modules/ping.pyis the upstreamansible.builtin.pingmodule (from ansible/ansible)- it takes
data(default:pong) and returns{"ping": <data>}viaexit_json
Notes
- real Ansible module execution requires
pyinfra[ansible] - SSH localhost E2E test is gated by
PYINFRA_E2E_SSH_LOCALHOST=1 - tested real Ansible module over SSH localhost
Validation
uv run pytest tests/test_operations_ansible.pyuv run pytest tests/test_operations.py -k ansible_moduleuv run pytest -m end_to_end_local -k ansibleuv run pyinfra -y -v localhost --ssh-user $(whoami) --ssh-key ~/.ssh/id_ed25519 --data ssh_allow_agent=false --data ssh_known_hosts_file=/dev/null --data ssh_strict_host_key_checking=no ansible.module examples/ansible_modules/ping.py data=pyinfra
Seems like 3.x is fine. Let me rebase
what's the current state of this PR?