Configuration Reference¶
Complete reference for all configuration properties.
Step Properties¶
Every step in your configuration can use these properties. Properties are grouped by function.
Quick Reference Table¶
| Property | Type | Applies To | Description |
|---|---|---|---|
| Identification | |||
name |
string | All | Human-readable step name |
| Actions (one required) | |||
shell |
string | Shell | Shell command to execute |
file |
object | File | File/directory operation |
template |
object | Template | Template rendering |
include |
string | Include | Include steps from another file |
include_vars |
string | Variables | Load variables from file |
vars |
object | Variables | Define inline variables |
| Control Flow | |||
when |
string | All | Conditional expression |
tags |
array[string] | All | Tags for filtering |
| Loops | |||
with_items |
string | All | Iterate over list |
with_filetree |
string | All | Iterate over directory |
| Privilege | |||
become |
boolean | shell, file, template | Execute with sudo |
become_user |
string | shell only | User for sudo (e.g., 'postgres') |
| Shell Execution Control | |||
env |
object | shell only | Environment variables |
cwd |
string | shell only | Working directory |
timeout |
string | shell only | Maximum execution time |
retries |
integer | shell only | Number of retry attempts |
retry_delay |
string | shell only | Delay between retries |
| Result Control | |||
changed_when |
string | shell only | Override changed status |
failed_when |
string | shell only | Override failure status |
register |
string | All | Variable name to store result |
Property Details¶
name¶
Type: string
Applies to: All actions
Required: No (but recommended)
Human-readable description displayed in output.
shell¶
Type: string
Applies to: Shell action
Required: When using shell action
Command to execute in bash shell.
- shell: echo "Hello"
# Multi-line
- shell: |
echo "Line 1"
echo "Line 2"
# With variables
- shell: echo "{{message}}"
Supports:
- Template variable substitution
- Multi-line commands with |
- All shell-specific fields
file¶
Type: object
Applies to: File action
Required: When using file action
File or directory operation.
Properties:
| Property | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File/directory path |
state |
string | No | file, directory, or absent |
content |
string | No | Content to write to file |
mode |
string | No | Permissions (e.g., "0644", "0755") |
# Create directory
- file:
path: /tmp/myapp
state: directory
mode: "0755"
# Create file with content
- file:
path: /tmp/config.txt
state: file
content: "key: value"
mode: "0644"
template¶
Type: object
Applies to: Template action
Required: When using template action
Render pongo2 template file.
Properties:
| Property | Type | Required | Description |
|---|---|---|---|
src |
string | Yes | Source template file path |
dest |
string | Yes | Destination file path |
vars |
object | No | Additional variables for template |
mode |
string | No | Permissions (e.g., "0644") |
- template:
src: ./config.yml.j2
dest: /etc/app/config.yml
mode: "0644"
vars:
port: 8080
debug: true
include¶
Type: string
Applies to: Include action
Required: When using include action
Path to YAML file containing steps to include.
- include: ./tasks/common.yml
# With condition
- include: ./tasks/linux.yml
when: os == "linux"
# With variables
- include: ./tasks/{{env}}.yml
include_vars¶
Type: string
Applies to: Variable loading action
Required: When using include_vars action
Path to YAML file containing variables to load.
vars¶
Type: object
Applies to: Variable definition action
Required: When using vars action
Define inline variables.
when¶
Type: string
Applies to: All actions
Required: No
Conditional expression. Step executes only if expression evaluates to true.
Operators: ==, !=, >, <, >=, <=, &&, ||, !
# OS check
- shell: brew install git
when: os == "darwin"
# Multiple conditions
- shell: install-package
when: os == "linux" && memory_total_mb >= 8000
# Using register results
- shell: which docker
register: docker_check
- shell: echo "Docker not found"
when: docker_check.rc != 0
tags¶
Type: array[string]
Applies to: All actions
Required: No
Tags for filtering step execution via --tags flag.
Usage:
# Run only dev steps
mooncake run --config config.yml --tags dev
# Multiple tags (OR logic)
mooncake run --config config.yml --tags dev,test
with_items¶
Type: string
Applies to: All actions
Required: No
Iterate over list. Step executes once for each item with {{item}} variable.
# List literal
- shell: echo "{{item}}"
with_items: [a, b, c]
# Variable reference
- vars:
packages: [git, vim, tmux]
- shell: brew install {{item}}
with_items: "{{packages}}"
with_filetree¶
Type: string
Applies to: All actions
Required: No
Iterate over files in directory tree. Step executes for each file.
Item properties:
- {{item.name}} - File name
- {{item.src}} - Full source path
- {{item.is_dir}} - Boolean, true if directory
- shell: cp "{{item.src}}" "/backup/{{item.name}}"
with_filetree: ./dotfiles
when: item.is_dir == false
become¶
Type: boolean
Applies to: shell, file, template actions
Required: No
Default: false
Execute step with sudo privileges.
Requirements:
- Must provide --sudo-pass flag or use --raw mode
- User must have sudo privileges
become_user¶
Type: string
Applies to: shell only
Required: No
Default: root
⚠️ Shell commands only - Ignored for file/template/include.
Specify user when using become. Only works with shell commands.
- name: Run as postgres user
shell: psql -c "SELECT version()"
become: true
become_user: postgres
- name: Run as app user
shell: ./manage.py migrate
become: true
become_user: appuser
env¶
Type: object (string keys and values)
Applies to: shell only
Required: No
⚠️ Shell commands only - Ignored for file/template/include.
Environment variables for shell command execution. Values support template rendering.
- shell: make build
env:
CC: gcc-11
CFLAGS: "-O2 -Wall"
PATH: "/custom/bin:$PATH"
PROJECT: "{{project_name}}"
cwd¶
Type: string
Applies to: shell only
Required: No
⚠️ Shell commands only - Ignored for file/template/include.
Working directory for shell command execution. Supports template rendering.
- shell: npm install
cwd: /opt/myproject
- shell: ./build.sh
cwd: "/home/{{user}}/projects/{{project}}"
timeout¶
Type: string (duration)
Applies to: shell only
Required: No
⚠️ Shell commands only - Ignored for file/template/include.
Maximum execution time. Command terminates with exit code 124 on timeout.
Format: Number + unit (ns, us, µs, ms, s, m, h)
- shell: ./slow-script.sh
timeout: 30s
- shell: npm run build
timeout: 10m
- shell: integration-tests
timeout: 1h
retries¶
Type: integer
Applies to: shell only
Required: No
Default: 0
Range: 0-100
⚠️ Shell commands only - Ignored for file/template/include.
Number of times to retry on failure. Total attempts = retries + 1.
- shell: curl https://api.example.com/data
retries: 3
- shell: docker pull myimage:latest
retries: 5
retry_delay: 10s
retry_delay¶
Type: string (duration)
Applies to: shell only
Required: No
Default: No delay
⚠️ Shell commands only - Ignored for file/template/include.
Delay between retry attempts. Only used when retries is set.
Format: Number + unit (ns, us, µs, ms, s, m, h)
changed_when¶
Type: string (expression)
Applies to: shell only
Required: No
⚠️ Shell commands only - Ignored for file/template/include.
Expression to override changed status. Evaluated after command execution.
Available variables:
- result.rc - Exit code
- result.stdout - Standard output
- result.stderr - Standard error
- result.failed - Boolean failure status
# Never changed
- shell: cat /etc/os-release
changed_when: false
# Git pull - only changed if updated
- shell: git pull
changed_when: "'Already up to date' not in result.stdout"
# Based on exit code
- shell: check-update
changed_when: "result.rc == 0"
failed_when¶
Type: string (expression)
Applies to: shell only
Required: No
⚠️ Shell commands only - Ignored for file/template/include.
Expression to override failure status. Evaluated after command execution.
Available variables: Same as changed_when
# Grep - 0=found, 1=not found, 2+=error
- shell: grep "pattern" file.txt
failed_when: "result.rc >= 2"
# Multiple acceptable exit codes
- shell: ./script.sh
failed_when: "result.rc not in [0, 2]"
# Check stderr
- shell: ./command
failed_when: "'ERROR' in result.stderr or 'FATAL' in result.stderr"
# Never fail (ignore errors)
- shell: best-effort-command
failed_when: false
register¶
Type: string
Applies to: All actions
Required: No
Variable name to store step execution result.
Result properties:
- rc - Exit code (0 = success)
- stdout - Standard output (shell only)
- stderr - Standard error (shell only)
- failed - Boolean, true if step failed
- changed - Boolean, true if step made changes
- shell: whoami
register: current_user
- shell: echo "User is {{current_user.stdout}}"
# Use in conditions
- shell: which docker
register: docker_check
- shell: echo "Docker not installed"
when: docker_check.rc != 0
System Facts Reference¶
Available automatically in all steps. View with mooncake explain.
Basic Facts¶
| Variable | Type | Example | Description |
|---|---|---|---|
os |
string | "linux", "darwin", "windows" |
Operating system |
arch |
string | "amd64", "arm64" |
CPU architecture |
hostname |
string | "myserver" |
System hostname |
user_home |
string | "/home/user" |
Current user's home directory |
Distribution Info¶
| Variable | Type | Example | Description |
|---|---|---|---|
distribution |
string | "ubuntu", "macos" |
OS distribution |
distribution_version |
string | "22.04", "13.0" |
Full version |
distribution_major |
string | "22", "13" |
Major version number |
Hardware Facts¶
| Variable | Type | Example | Description |
|---|---|---|---|
cpu_cores |
integer | 8 |
Number of CPU cores |
memory_total_mb |
integer | 16384 |
Total RAM in MB |
Software Detection¶
| Variable | Type | Example | Description |
|---|---|---|---|
package_manager |
string | "apt", "brew", "yum" |
Detected package manager |
python_version |
string | "3.10.0" |
Python version (if installed) |
Network Facts¶
| Variable | Type | Example | Description |
|---|---|---|---|
ip_addresses |
array | ["192.168.1.100"] |
List of IP addresses |
ip_addresses_string |
string | "192.168.1.100" |
First IP address |
File Mode Reference¶
Common permission values for mode property:
| Mode | Permissions | Use Case |
|---|---|---|
"0755" |
rwxr-xr-x |
Directories, executables |
"0644" |
rw-r--r-- |
Regular files, configs |
"0600" |
rw------- |
Private files, secrets |
"0700" |
rwx------ |
Private directories |
"0777" |
rwxrwxrwx |
World-writable (avoid!) |
Expression Syntax Reference¶
Used in when, changed_when, failed_when.
Operators¶
| Operator | Description | Example |
|---|---|---|
== |
Equals | os == "linux" |
!= |
Not equals | arch != "arm64" |
> |
Greater than | memory_total_mb > 8000 |
< |
Less than | cpu_cores < 4 |
>= |
Greater or equal | distribution_major >= "20" |
<= |
Less or equal | cpu_cores <= 16 |
&& |
Logical AND | os == "linux" && arch == "amd64" |
|| |
Logical OR | os == "linux" || os == "darwin" |
! |
Logical NOT | !(os == "windows") |
in |
Contains (lists) | result.rc in [0, 2] |
not in |
Not contains | result.rc not in [1, 2] |
Special Values¶
| Value | Description |
|---|---|
true |
Boolean true |
false |
Boolean false |
"string" |
String literal (single or double quotes) |
123 |
Number literal |
See Also¶
- Actions Guide - Detailed action documentation
- Control Flow Guide - Conditionals, loops, tags
- Variables Guide - Variable management
- Examples - Practical examples