pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Add best-effort Ansible module bridge operation

Open JakkuSakura opened this issue 9 months ago • 2 comments

Summary

  • add ansible.module(...) that executes real Ansible modules on the target host (upload module + ansible module_utils/_vendor, run with stdin JSON)
  • add optional extra pyinfra[ansible] and include ansible in test deps
  • update local E2E and examples to use ansible.module with ansible.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.py is the upstream ansible.builtin.ping module (from ansible/ansible)
  • it takes data (default: pong) and returns {"ping": <data>} via exit_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.py
  • uv run pytest tests/test_operations.py -k ansible_module
  • uv run pytest -m end_to_end_local -k ansible
  • uv 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

JakkuSakura avatar Feb 13 '26 10:02 JakkuSakura

Seems like 3.x is fine. Let me rebase

JakkuSakura avatar Mar 25 '26 10:03 JakkuSakura

what's the current state of this PR?

Dexmachi avatar Apr 28 '26 11:04 Dexmachi