Skip to main content

Small Ansible - Minimal Ansible-compatible runner for Windows and Linux

Project description

Sansible

Python 3.9+ Pure Python License: MIT Tests

A minimal, pure-Python Ansible runner for Windows and Linux

Sansible runs Ansible playbooks natively on Windows without WSL, targeting both Windows (WinRM) and Linux (SSH) hosts. It delivers 80% of Ansible's value with 20% of the code.

โœจ Highlights

  • ๐ŸชŸ Windows Native โ€” Run as a control node on Windows, no WSL required
  • ๐Ÿ Pure Python โ€” Ships as py3-none-any wheel, no compiled extensions
  • ๐Ÿš€ Fast Setup โ€” pip install sansible and you're ready
  • ๐Ÿ“ฆ Ansible Compatible โ€” Uses the same playbook/inventory syntax
  • ๐ŸŽฏ 63 Modules โ€” Core modules for real-world automation
  • ๐Ÿ”Œ Galaxy FQCN Support โ€” Use ansible.builtin.* and ansible.windows.* FQCNs

๐Ÿš€ Quick Start

Installation

# Basic installation (local execution only)
pip install sansible

# With SSH support (Linux/Unix targets)
pip install "sansible[ssh]"

# With WinRM support (Windows targets)
pip install "sansible[winrm]"

# Full installation (all transports)
pip install "sansible[all]"

Your First Playbook

Create hello.yml:

---
- name: Hello World
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Say hello
      debug:
        msg: "Hello from Sansible!"
    
    - name: Run a command
      command: echo "It works!"
      register: result
    
    - name: Show result
      debug:
        var: result.stdout

Run it:

sansible-playbook -i localhost, hello.yml

๐Ÿ“Š Module Compatibility Matrix

โœ… Tested and Working (Live System Verified)

All modules have been tested on live Linux (RHEL 8.5) and Windows (Server 2019) systems.

Linux Modules

Module Status Notes
ping โœ… Tested Returns pong
debug โœ… Tested msg, var output
command โœ… Tested Execute commands
shell โœ… Tested Shell expansion works
raw โœ… Tested Raw command execution
copy โœ… Tested content, src/dest
file โœ… Tested directory, touch, absent
stat โœ… Tested File info retrieval
slurp โœ… Tested Read file content (base64)
template โœ… Tested Jinja2 templating
lineinfile โœ… Tested Line management
blockinfile โœ… Tested Block management
replace โœ… Tested Regex replacement
find โœ… Tested File discovery
tempfile โœ… Tested Create temp files
set_fact โœ… Tested Variable setting
assert โœ… Tested Condition assertion
fail โœ… Tested Intentional failure
wait_for โœ… Tested Port/file waiting
pause โœ… Tested Execution pause
include_vars โœ… Tested Load YAML vars
meta โœ… Tested noop action
setup โœ… Tested Fact gathering
service โœ… Tested Service management (check mode)
user โœ… Tested User management (check mode)
group โœ… Tested Group management (check mode)
script โš ๏ธ Partial Requires local script file
fetch โœ… Tested Download files from remote
get_url โœ… Available Download from URL
uri โœ… Available HTTP requests
apt โœ… Available Debian package management
yum โœ… Available RedHat package management
dnf โœ… Available Fedora package management
pip โœ… Available Python package management
git โœ… Available Git operations
cron โœ… Available Cron job management
systemd โœ… Available Systemd service management
hostname โœ… Available Hostname management
known_hosts โœ… Available SSH known hosts
unarchive โœ… Available Archive extraction
add_host โœ… Available Dynamic inventory
group_by โœ… Available Dynamic grouping
getent โœ… Available Name service lookup
reboot โœ… Available System reboot
wait_for_connection โœ… Available Connection waiting

Windows Modules

Module Status Notes
win_ping โœ… Tested Returns pong
win_command โœ… Tested Execute commands
win_shell โœ… Tested PowerShell execution
win_copy โœ… Tested File copy with content
win_file โœ… Tested directory, absent states
win_stat โœ… Tested File info retrieval
win_slurp โœ… Tested Read file content
win_lineinfile โœ… Tested Line management
win_service โœ… Tested Service management
win_wait_for โœ… Tested Port/file waiting
win_template โš ๏ธ Partial Requires local template
win_reboot โœ… Tested System reboot (check mode)
win_user โœ… Available User management
win_group โœ… Available Group management
win_get_url โœ… Available Download from URL

Galaxy FQCN Support

Sansible supports Fully Qualified Collection Names (FQCNs):

FQCN Pattern Status Notes
ansible.builtin.* โœ… Tested Maps to native modules
ansible.windows.* โœ… Tested Maps to native win_* modules
ansible.posix.* โœ… Tested Remote execution on Linux
community.general.* โœ… Available Remote execution on Linux
# All these work identically:
- ansible.builtin.copy:
    content: "hello"
    dest: /tmp/test.txt

- copy:
    content: "hello"
    dest: /tmp/test.txt

See docs/GALAXY.md for full Galaxy support details.


๐Ÿ”ง Playbook Features

โœ… Fully Working

Feature Status Live Tested
Multiple plays โœ… Yes
Variables (vars, vars_files) โœ… Yes
Conditionals (when) โœ… Yes
Loops (loop, with_items) โœ… Yes
Register results โœ… Yes
changed_when / failed_when โœ… Yes
ignore_errors โœ… Yes
Fact gathering (gather_facts) โœ… Yes
Handlers (notify) โœ… Yes
Check mode (--check) โœ… Yes
Diff mode (--diff) โœ… Yes
Extra vars (-e) โœ… Yes
Tags (--tags, --skip-tags) โœ… Yes
Limit (--limit, -l) โœ… Yes
Verbose (-v, -vv, -vvv) โœ… Yes
JSON output (--json) โœ… Yes

โœ… Working with Notes

Feature Status Notes
become (sudo) โœ… Requires ansible_become_password
delegate_to โœ… Tested with localhost
include_tasks / import_tasks โœ… Task file inclusion
include_role / import_role โœ… Role inclusion
block/rescue/always โš ๏ธ Block works, rescue needs review
Vault (--vault-password-file) โœ… Requires cryptography
Roles โœ… tasks, defaults, vars, handlers
Dynamic inventory โœ… JSON format scripts

โŒ Not Supported

Feature Reason
async / poll Complexity, limited use
Galaxy collections install Out of scope
Callbacks/Plugins Architecture
Molecule testing External tool
sansible / sansible-inventory CLIs Ad-hoc/inventory entrypoints currently placeholders

๐Ÿ“‹ Jinja2 Filters

โœ… Available Filters

Filter Example Status
default / d {{ var | default('fallback') }} โœ…
lower {{ name | lower }} โœ…
upper {{ name | upper }} โœ…
trim {{ text | trim }} โœ…
replace {{ text | replace('a', 'b') }} โœ…
to_json {{ dict | to_json }} โœ…
to_yaml {{ dict | to_yaml }} โœ…
bool {{ 'yes' | bool }} โœ…
int {{ '42' | int }} โœ…
string {{ 42 | string }} โœ…
length {{ list | length }} โœ…
join {{ list | join(',') }} โœ…
first {{ list | first }} โœ…
last {{ list | last }} โœ…
basename {{ path | basename }} โœ…
dirname {{ path | dirname }} โœ…
regex_replace {{ text | regex_replace('pattern', 'replace') }} โœ…
b64decode {{ encoded | b64decode }} โœ…
b64encode {{ text | b64encode }} โœ…

๐Ÿงช Test Results

Unit Tests: 269 Passed โœ…

tests/unit/test_become.py                    - 8 tests  โœ…
tests/unit/test_block.py                     - 5 tests  โœ…
tests/unit/test_block_execution.py           - 6 tests  โœ…
tests/unit/test_check_diff_mode.py           - 10 tests โœ…
tests/unit/test_executor_linear.py           - 12 tests โœ…
tests/unit/test_galaxy.py                    - 32 tests โœ…
tests/unit/test_handlers.py                  - 8 tests  โœ…
tests/unit/test_include_tasks.py             - 5 tests  โœ…
tests/unit/test_inventory.py                 - 9 tests  โœ…
tests/unit/test_lineinfile_module.py         - 10 tests โœ…
tests/unit/test_playbook_parse.py            - 12 tests โœ…
tests/unit/test_playbook_roles.py            - 7 tests  โœ…
tests/unit/test_runner.py                    - 6 tests  โœ…
tests/unit/test_stat_module.py               - 6 tests  โœ…
tests/unit/test_tags_limit.py                - 8 tests  โœ…
tests/unit/test_templating.py                - 25 tests โœ…
tests/unit/test_vault.py                     - 12 tests โœ…
tests/unit/test_wait_for_module.py           - 6 tests  โœ…
tests/unit/test_win_service.py               - 8 tests  โœ…
... and more

Live System Tests

Linux (RHEL 8.5, 192.168.10.181)

  • SSH Connection: โœ…
  • Command modules: โœ…
  • File modules: โœ…
  • gather_facts: โœ…
  • Handlers: โœ…
  • Galaxy FQCN: โœ…

Windows (Server 2019, 192.168.100.3)

  • WinRM Connection: โœ…
  • win_* modules: โœ…
  • gather_facts: โœ…
  • Galaxy FQCN: โœ…

๐Ÿ“– Examples

The examples/playbooks/ directory contains runnable examples:

Playbook Features
01_basics.yml debug, set_fact, command, shell
02_conditionals.yml when, loop, register
03_file_management.yml file, copy, stat, lineinfile
04_handlers.yml handlers, notify
05_blocks.yml block, rescue, always
06_become.yml become (sudo)
07_gather_facts.yml gather_facts, setup
win_01_basics.yml win_command, win_shell
win_02_services.yml win_service
win_03_files.yml win_stat, win_lineinfile
sansible-playbook -i examples/playbooks/inventory.ini examples/playbooks/01_basics.yml

๐Ÿ›  CLI Reference

sansible-playbook -i INVENTORY PLAYBOOK [OPTIONS]

Options:
  -i, --inventory FILE    Inventory file (required)
  -l, --limit PATTERN     Limit to matching hosts
  -t, --tags TAGS         Only run tagged tasks
  --skip-tags TAGS        Skip tagged tasks
  -e, --extra-vars VARS   Extra variables (JSON or key=value)
  -f, --forks N           Parallel limit (default: 5)
  -C, --check             Dry-run mode
  --diff                  Show file changes
  --json                  JSON output
  --vault-password-file   Vault password file
  --ask-vault-pass        Prompt for vault password
  -v/-vv/-vvv             Verbosity

Examples

# Basic execution
sansible-playbook -i inventory.ini playbook.yml

# Limit to hosts
sansible-playbook -i inventory.ini playbook.yml -l webservers

# Check mode with diff
sansible-playbook -i inventory.ini playbook.yml --check --diff

# Extra variables
sansible-playbook -i inventory.ini playbook.yml -e '{"version": "2.0"}'

# JSON output
sansible-playbook -i inventory.ini playbook.yml --json

๐Ÿ“Š Exit Codes

Code Meaning
0 Success
2 Host failure(s)
3 Parse/syntax error
4 Unsupported feature

๐Ÿ”ง Development

# Clone
git clone https://github.com/small-ansible/sansible.git
cd sansible

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/unit/ -v

# Build wheel
pip wheel . -w dist/

Quick Dev Setup with uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh
git clone https://github.com/small-ansible/sansible.git && cd sansible
uv venv && source .venv/bin/activate
uv pip install -e ".[dev,ssh,winrm]"
pytest tests/unit/ -q --tb=no

Windows (PowerShell):

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
git clone https://github.com/small-ansible/sansible.git; cd sansible
uv venv; .\.venv\Scripts\Activate.ps1
uv pip install -e ".[dev,ssh,winrm]"
pytest tests/unit/ -q --tb=no

AI Agent Testing

For automated testing with AI agents, use the prompts in .github/:

Prompt Use Case
AGENT_TEST_PROMPT.md Windows control node
AGENT_TEST_PROMPT_LINUX.md Linux control node
# Fetch and follow the prompt:
curl -s https://raw.githubusercontent.com/small-ansible/sansible/main/.github/AGENT_TEST_PROMPT_LINUX.md

๐Ÿ“š Documentation


๐Ÿ“„ License

MIT License โ€” See LICENSE for details.


Made with โค๏ธ for DevOps engineers who need to run playbooks on Windows.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sansible-0.4.1.tar.gz (133.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sansible-0.4.1-py3-none-any.whl (178.6 kB view details)

Uploaded Python 3

File details

Details for the file sansible-0.4.1.tar.gz.

File metadata

  • Download URL: sansible-0.4.1.tar.gz
  • Upload date:
  • Size: 133.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sansible-0.4.1.tar.gz
Algorithm Hash digest
SHA256 82b8faf3952d13937342e6872b0297a12c80ae0c71bc31aed8bca1d269844d52
MD5 f47c3bd2b195412fe8088edc29635ee7
BLAKE2b-256 c9f8ca935a97a1e8f7ad68414758f6c624e6127325a4bc52526688f45ae61715

See more details on using hashes here.

File details

Details for the file sansible-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: sansible-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 178.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sansible-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a27834cad762745a1785d17be1790fe1067fdad0ea9b585e04b86bab98338e9
MD5 d69a8f74a87d0058d4a856b2ed82d618
BLAKE2b-256 2c32712dfe593cc4dabba279a8fd54375c83d1881632d81a04b22d1b7ca6384a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page