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...
- 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
whenclauses 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.
puppet2ansible/parser.py— Parses Puppet manifestsmapper.py— Maps Puppet resources to Ansible moduleslogic.py— Converts Puppet logic and generates handlerstemplate.py— Handles template conversioncli.py— Command-line interface
.github/copilot-instructions.md— Project instructions
- Install Python 3.11+ and pip. (I grabbed mine from the latest version in the Microsoft Store, thanks VSCode!)
- Install dependencies:
pip install -r requirements.txt
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.
<input.pp>: Path to the Puppet manifest file to convert<output.yml>: Path to the output Ansible playbook file
--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
python -m puppet2ansible.cli example.pp example_output.yml --suppress-warnings --handler-action debugYou can display usage and argument information with:
python -m puppet2ansible.cli -hExample 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
- Improve parsing for complex manifests
- Expand resource mapping coverage
- Enhance template and logic conversion
MIT
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.