Write an action
on this page
Package a task sequence behind named inputs so several playbooks can reuse it. Keep logic that only one playbook needs inline in that playbook.
1. Create the action directory
Project-local actions live under actions/ in the project root:
text
actions/
myorg/
display-config/
action.ymlThe directory path under actions/ is the ref: myorg/display-config.
2. Define action.yml
yaml
name: myorg/display-config
version: "1.0.0"
description: Prepare a content directory and drop a marker file
inputs:
content_root:
type: path
required: true
description: Target content directory
label:
type: string
default: default
description: Marker text
tasks:
- name: Ensure content directory exists
directory:
path: "{{ vars.content_root }}"
ensure: present
- name: Write content marker
file:
dest: "{{ vars.content_root }}\\marker.txt"
content: "{{ vars.label }}"- Set
nameto the ref. inputsdeclares the values callers pass. Each has atype(string,bool,int,path, orlist), and can berequiredor have adefault.- Tasks read inputs as
vars.<input>. - Tasks use the same schema as playbook tasks.
3. Call the action from a playbook
yaml
tasks:
- name: Prepare lobby content
uses: myorg/display-config
with:
content_root: "C:\\Exhibits\\Lobby"
label: lobbyDuring planning, Preflight renders the with: values, applies defaults, rejects missing required inputs, and expands the action’s tasks into the plan.
4. Inspect the action
bash
preflight action list
preflight action info myorg/display-configaction info shows the action’s name, inputs, and task names.
5. Validate the calling playbook
bash
preflight validate playbooks/lobby.yml
preflight plan playbooks/lobby.ymlvalidate checks the playbook and the action ref. plan shows the expanded tasks.
Notes
- Preflight resolves refs from the embedded stdlib (
preflight/...) first, then localactions/, then the user cache, then Git-backed refs. - To share an action across projects, publish it in a Git repository and reference it remotely. See Update and pin remote actions.