Skip to content

ha3ks/Puppet2Ansible

Repository files navigation

Puppet to Ansible Converter

Overview

Puppet2Ansible is a Python tool that automatically converts Puppet manifests (.pp files) into Ansible playbooks (.yml). It parses Puppet resources, logic, and templates, mapping them to equivalent Ansible modules and tasks. The goal is to provide a one-step, automated migration path from Puppet to Ansible, supporting simple to highly complex manifests.

I don't know why I made this, I just saw that it was on a lot of job listings so I'm making my life easier, or alternatively I am screwing myself out of a job...

How It Works

  • Parsing: Extracts resources, logic blocks, and templates from Puppet manifests.
  • Mapping: Translates Puppet resources (file, package, service, user, group, cron, exec, notify, etc.) to Ansible modules.
  • Logic Conversion: Converts Puppet conditionals (if/case) to Ansible when clauses and generates handlers for notifications.
  • Template Conversion: Converts ERB templates to Jinja2 (basic support).
  • Error Handling: Unsupported features are flagged with warnings or manual review comments.

Project Structure

  • puppet2ansible/
    • parser.py — Parses Puppet manifests
    • mapper.py — Maps Puppet resources to Ansible modules
    • logic.py — Converts Puppet logic and generates handlers
    • template.py — Handles template conversion
    • cli.py — Command-line interface
  • .github/copilot-instructions.md — Project instructions

Installation

  1. Install Python 3.11+ and pip. (I grabbed mine from the latest version in the Microsoft Store, thanks VSCode!)
  2. Install dependencies:
    pip install -r requirements.txt

Usage

Run the CLI to convert a Puppet manifest to an Ansible playbook:

python -m puppet2ansible.cli <input.pp> <output.yml> [--suppress-warnings] [--handler-action ACTION]

By default, the converter will display warnings for unsupported or partially supported features after conversion. If you want to suppress these warnings, use the --suppress-warnings argument.

Arguments

  • <input.pp>: Path to the Puppet manifest file to convert
  • <output.yml>: Path to the output Ansible playbook file

Options

  • --suppress-warnings: Suppress warnings for unsupported or partially supported features
  • --handler-action ACTION: Specify a custom handler action (default: debug)
  • -h, --help: Show help message and usage information

Example

python -m puppet2ansible.cli example.pp example_output.yml --suppress-warnings --handler-action debug

CLI Help

You can display usage and argument information with:

python -m puppet2ansible.cli -h

Example output:

puppet2ansible CLI
------------------
Convert Puppet manifests (.pp) to Ansible playbooks (.yml).

Usage:
  python -m puppet2ansible.cli <input.pp> <output.yml> [--suppress-warnings] [--handler-action ACTION]

Arguments:
  input.pp            Input Puppet manifest file
  output.yml          Output Ansible playbook file

Options:
  --suppress-warnings   Suppress warnings for known safe conversions
  --handler-action      Custom handler action (default: debug)
  -h, --help            Show this help message and exit

Roadmap

  • Improve parsing for complex manifests
  • Expand resource mapping coverage
  • Enhance template and logic conversion

License

MIT

Example Puppet Manifests

A set of example Puppet manifest files is included in this repository (e.g., simple_test.pp, complex_test.pp, difficult_test.pp). You can run the converter on these files to see how the tool works and view the resulting Ansible playbooks. This is useful for learning, testing, and validating the conversion process.

About

Python Script to convert .pp files into workable .yml files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors