A sophisticated Ansible callback plugin that formats output for optimal display in GitHub Actions workflow logs, featuring smart grouping, comprehensive status mapping, and detailed statistics tracking.
- Smart Grouping: Automatically adapts folding strategy based on host count
- Single host: Groups by play for logical progression view
- Multiple hosts: Groups by task to show parallel execution clearly
- GitHub Actions Integration: Full support for workflow commands (
::group::,::notice::,::warning::,::error::) - Comprehensive Status Mapping:
ok→::notice::(blue info)changed→::warning::(yellow warning)failed→::error::(red error)unreachable→::error::(red error)skipped→ plain text (no formatting)
- Statistics Tracking: Detailed per-play and per-host statistics
- Archive Support: Optional output archiving to file
- Configurable: Supports both environment variables and ansible.cfg configuration
- Copy
github_actions.pyto your project directory - Configure in
ansible.cfg:[defaults] stdout_callback = github_actions callback_plugins = ./ [callback_github_actions] grouping = smart verbose = true archive_file = /tmp/ansible_output.log
- Run your playbook - output will be automatically formatted for GitHub Actions!
GITHUB_ACTIONS_GROUPING:smart(default),play, ortaskGITHUB_ACTIONS_VERBOSE:trueorfalse(default)GITHUB_ACTIONS_ARCHIVE_FILE: Path to archive file (optional)
[callback_github_actions]
grouping = smart # Grouping mode
verbose = true # Enable debug output
archive_file = /tmp/ansible_output.log # Archive file path# Single host - uses play grouping
ansible-playbook -i host1, playbook.yml
# Multiple hosts - uses task grouping
ansible-playbook -i host1,host2,host3, playbook.yml- Single Host: Groups by play - shows logical flow through configuration steps
- Multiple Hosts: Groups by task - shows which hosts completed each step
Forces play-level grouping regardless of host count. Best for sequential workflows.
Forces task-level grouping regardless of host count. Best for parallel operations.
The test/ directory contains comprehensive testing tools:
cd test/
python3 -m pytest test_github_actions.py -vcd test/
# Test single host (play grouping)
ansible-playbook -i 127.0.0.1, main.yml
# Test multiple hosts (task grouping)
ansible-playbook -i 127.0.0.1,127.0.0.2,127.0.0.3, main.yml
# Run full test suite
./run_tests.shtest_github_actions.py- Comprehensive unit teststest_grouping.py- Grouping functionality teststest_output.py- Output formatting teststest_changed_fix.py- Changed detection teststest_unreachable.py- Unreachable host testsmain.yml- Demo playbook showcasing featuresrun_tests.sh- Automated test script
::group::Play: Deploy Application
::notice::tasks/setup.yml | web-server | ok | Deploy Application | Install packages
::warning::tasks/config.yml | web-server | changed | Deploy Application | Update config
::notice::tasks/service.yml | web-server | ok | Deploy Application | Start service
::endgroup::
::group::Play: Deploy Application
::notice::tasks/setup.yml | web-01 | ok | Deploy Application | Install packages
::endgroup::
::group::Install packages
::notice::tasks/setup.yml | web-02 | ok | Deploy Application | Install packages
::notice::tasks/setup.yml | web-03 | ok | Deploy Application | Install packages
::endgroup::
::group::Update config
::warning::tasks/config.yml | web-01 | changed | Deploy Application | Update config
::error::tasks/config.yml | web-02 | unreachable | Deploy Application | Update config
::warning::tasks/config.yml | web-03 | changed | Deploy Application | Update config
::endgroup::
# .github/workflows/deploy.yml
- name: Run Ansible Playbook
run: |
export GITHUB_ACTIONS_GROUPING=smart
export GITHUB_ACTIONS_VERBOSE=true
ansible-playbook -i inventory playbook.ymlThe plugin gracefully handles:
- Missing file paths
- Network connectivity issues
- Invalid task results
- Archive file I/O errors
- Minimal overhead - only formats output that would be displayed anyway
- Efficient grouping decisions
- Optional archiving doesn't impact execution speed
| Issue | Solution |
|---|---|
| Plugin not loading | Check callback_plugins path in ansible.cfg |
| No formatting | Verify stdout_callback = github_actions |
| Archive errors | Ensure archive file path is writable |
| Grouping issues | Enable verbose mode for debugging |
| Missing statistics | Check for early playbook termination |
- Run tests:
cd test && python3 -m pytest test_github_actions.py -v - Test live demo:
cd test && ./run_tests.sh - Update documentation as needed
- Submit pull request with test coverage
This project follows standard open source practices. See repository for license details.