A C implementation of a Puppet language parser and interpreter using flex/bison.
Note: This is an experimental project. It implements a subset of the Puppet language and is not a replacement for the real Puppet.
Prerequisites:
- GCC, flex, bison
- Ruby development headers (for ERB templates)
- libyaml (for Hiera)
- libssl/openssl (for crypto functions)
- libmicrohttpd (for puppetc-server)
- libcurl (for puppetc-agent)
autoreconf -i
./configure
make
make checkBuild and run using Docker (no dependencies needed on host).
Sample manifests, modules, and hiera data are provided in docker/.
# Build images
docker build --target server -t puppetc-server .
docker build --target agent -t puppetc-agent .
# Run server with sample manifests
docker run -d -p 8140:8140 \
-v ./docker/manifests:/etc/puppet/manifests:ro \
puppetc-server
# Run agent (noop mode)
docker run --rm --network host puppetc-agent -n
# Run agent (apply mode)
docker run --rm --network host puppetc-agent -aOr use docker-compose (uses docker/ sample data):
# Start server
docker-compose up -d server
# Run agent in noop mode
docker-compose run agent
# Run agent in apply mode
docker-compose run agent -a# Parse only
./src/puppetc manifest.pp
# Parse and evaluate
./src/puppetc -e manifest.pp
# With facts
./src/puppetc -e -f facts.json manifest.pp
# JSON AST output
./src/puppetc -j manifest.ppRun ./src/puppetc --help for all options.
# Start server
./server/puppetc-server -p 8140 /etc/puppet/manifests
# Compile catalog via API
curl -X POST http://localhost:8140/puppet/v4/catalog \
-H 'Content-Type: application/json' \
-d '{"certname": "node1.example.com"}'# Show all facts
./facter/facter_c
# Specific facts
./facter/facter_c hostname ipaddress osfamily
# JSON output
./facter/facter_c -j# Run agent (connects to localhost:8140)
./agent/puppetc-agent
# Apply catalog resources
./agent/puppetc-agent -a
# No-op mode (show what would change)
./agent/puppetc-agent -n
# Specify server
./agent/puppetc-agent -s http://puppet:8140 -a
# Just show collected facts
./agent/puppetc-agent -f- Basic parsing of classes, resources, nodes, defines
- Conditionals: if/elsif/else, unless, case, ternary, selector
- Variable scoping and interpolation
- ERB templates (via embedded Ruby)
- Hiera lookups (YAML backend)
- Module autoloading
- Many stdlib functions (see below)
- Class instantiation with single quotes may fail due to parser ambiguity:
# Use double quotes: class { "apache": }
- No resource catalog generation
- No PuppetDB support
- Incomplete stdlib coverage
- Many edge cases not handled
Logging: notice, info, warning, debug, err, fail
Strings: split, join, chomp, strip, upcase, downcase, capitalize, match, regsubst
Arrays: concat, flatten, unique, sort, reverse, first, last, length, member, range
Hashes: keys, values, has_key, merge
Numeric: abs, floor, ceil, round, sqrt, min, max
Types: is_string, is_array, is_hash, is_numeric, is_bool, defined
Path: basename, dirname, extname
Crypto: sha1, md5, base64
Data: lookup
┌─────────────────────────────────────────────────────────────┐
│ Libraries │
├─────────────────────┬───────────────────────────────────────┤
│ libpuppetc │ libfacter_c │
│ - Parser/Lexer │ - Native fact collection │
│ - AST │ - JSON fact loading │
│ - Interpreter │ - System info (hostname, os, etc.) │
│ - Stdlib │ │
│ - Hiera │ │
│ - Catalog builder │ │
└─────────────────────┴───────────────────────────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ puppetc-server │ │ puppetc-agent │ │ puppetc │
│ │ │ │ │ (debug tool) │
│ - REST API │ │ - Collect facts │ │ - Parse/eval │
│ - Compile │ │ - Request catalog│ │ - JSON output │
│ catalogs │ │ - Apply catalog │ │ - Template debug│
└─────────────────┘ └──────────────────┘ └─────────────────┘