Skip to content

feat(infra): Replace Ansible Implementation with Ansible Runner#4220

Closed
tanmoysrt wants to merge 9 commits intofrappe:developfrom
tanmoysrt:ansible_play_refactor
Closed

feat(infra): Replace Ansible Implementation with Ansible Runner#4220
tanmoysrt wants to merge 9 commits intofrappe:developfrom
tanmoysrt:ansible_play_refactor

Conversation

@tanmoysrt
Copy link
Member

@tanmoysrt tanmoysrt commented Dec 15, 2025

Copied from https://github.com/adityahase/pilot/blob/ab1811abc64f57676fa466b59d9e0f7b1b3fb712/pilot/infrastructure/ansible.py

  • Refactored Ansible & AnsibleAdHoc implementation in press/runner.py with ansible-runner
  • Added support to run temporary playbook with AnsibleAdHoc
  • In SSH Access Audit , replaced duplicate implementation with AnsibleAdHoc with new one.

Dependencies -

ansible==10.7.0
ansible-runner==2.4.2
  • ansible 10.7.0 is the last version which supports python 3.10.
  • ansible 10.7.0 works with latest ubuntu / debian releases (tested with 24.04 | Python - 3.12.3)

Tests -

  • Generic Run Playbook and output
  • Ansible Ad Hoc Command
  • SSH Access Audit
  • Setup Server Play
  • Physical Backup / Restoration
  • Auto Scale

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 48.01223% with 170 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.94%. Comparing base (3229878) to head (682854d).
⚠️ Report is 1154 commits behind head on develop.

Files with missing lines Patch % Lines
press/runner.py 51.76% 137 Missing ⚠️
...cture/doctype/ssh_access_audit/ssh_access_audit.py 6.25% 30 Missing ⚠️
...s/press/doctype/ansible_console/ansible_console.py 75.00% 2 Missing ⚠️
press/press/doctype/ansible_play/ansible_play.py 50.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (48.01%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4220      +/-   ##
===========================================
- Coverage    50.98%   50.94%   -0.05%     
===========================================
  Files          836      836              
  Lines        66387    66431      +44     
  Branches       286      286              
===========================================
- Hits         33850    33844       -6     
- Misses       32509    32559      +50     
  Partials        28       28              
Flag Coverage Δ
dashboard 71.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Systemd-timesyncd is installed by default
In newer versions of os and that cause conflict
@tanmoysrt tanmoysrt force-pushed the ansible_play_refactor branch from a2998a6 to 681bccb Compare December 15, 2025 15:32
On ubuntu 20.04, the service name is ssh.service
instead of sshd.service

So, try to figure out the servic and then reload
@tanmoysrt tanmoysrt requested a review from ssiyad December 16, 2025 06:57
@tanmoysrt tanmoysrt marked this pull request as draft December 16, 2025 10:52
@0spinboson
Copy link
Contributor

I found a few bugs while reviewing and wrote fixes + tests in #5024:

Bugs fixed:

  1. Inventory trailing commainventory=f"{self.host}:{self.port}" needs a trailing comma (f"{self.host}:{self.port},") or ansible treats the string as a file path instead of a host list
  2. Inverted verbosityverbosity=0 if self.debug else 1 should be 1 if self.debug else 0
  3. Async job_id silently lost — when an async task starts, the initial runner_on_ok event contains ansible_job_id in res, but runner_on_ok doesn't save it, so downstream polling jobs can't find the job
  4. Importfrom ansible.inventory.manager import os works but should just be import os

Also added 20 unit tests for the pure-logic methods (_parse_tasks, inventory format, generate_cmdline, duration parsing, event dispatch, async detection).

Feel free to cherry-pick or I can rebase onto your branch.

@tanmoysrt
Copy link
Member Author

will reopen if required

@tanmoysrt tanmoysrt closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants