Skip to content

Add best-effort Ansible module bridge operation#1557

Open
JakkuSakura wants to merge 6 commits intopyinfra-dev:3.xfrom
JakkuSakura:ansible
Open

Add best-effort Ansible module bridge operation#1557
JakkuSakura wants to merge 6 commits intopyinfra-dev:3.xfrom
JakkuSakura:ansible

Conversation

@JakkuSakura
Copy link
Copy Markdown
Contributor

@JakkuSakura JakkuSakura commented Feb 13, 2026

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

Copy link
Copy Markdown
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woa this is wild @JakkuSakura! SUPER interesting. Should we merge this against 3.x? There's nothing 4-specific here?

@JakkuSakura
Copy link
Copy Markdown
Contributor Author

Seems like 3.x is fine. Let me rebase

@JakkuSakura JakkuSakura changed the base branch from 4.x to 3.x March 25, 2026 10:10
@JakkuSakura JakkuSakura marked this pull request as ready for review March 26, 2026 14:08
@Dexmachi
Copy link
Copy Markdown
Contributor

what's the current state of this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants