> ## Documentation Index
> Fetch the complete documentation index at: https://ona.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Automations as Code

> Define, version, and share Automations using YAML files and the Ona CLI.

Define Automations as YAML files and manage them with the Ona CLI.

## Why define Automations as code

* **Version control.** Track changes in Git. Review diffs, revert mistakes, use branches.
* **Reproducibility.** The YAML file is the source of truth. No UI clicks to reconstruct a lost Automation.
* **Distribution.** Commit Automation files to any repository. Team members run `ona ai automation create` to instantiate them.

## Prerequisites

* [Ona CLI](/ona/integrations/cli) installed and authenticated (`ona login`)

## Discover the YAML syntax

Generate a reference file covering the full syntax:

```bash theme={null}
ona ai automation create --example > automation.yaml
```

## Create an Automation from a file

```bash theme={null}
ona ai automation create automation.yaml
```

On success, the CLI prints the new Automation ID:

```
Successfully created ai automation a1b2c3d4-5e6f-7890-abcd-ef1234567890
```

Stdin is also supported:

```bash theme={null}
cat automation.yaml | ona ai automation create -
```

## Update an existing Automation

Find the Automation ID:

```bash theme={null}
ona ai automation list
```

Apply the updated file:

```bash theme={null}
ona ai automation update <automation-id> automation.yaml
```

Provided fields replace existing values. Fields not in the YAML remain unchanged. Complex fields like `triggers` and `action` are replaced entirely, not merged.

## Real-world example

[ona-samples/github-security](https://github.com/ona-samples/github-security) contains two Automation files that pick the highest-severity open security alert, fix it, run tests, and open a PR:

* [`.ona/fix-dependabot-alert.yaml`](https://github.com/ona-samples/github-security/blob/main/.ona/fix-dependabot-alert.yaml) — upgrades vulnerable dependencies flagged by Dependabot
* [`.ona/fix-codescan-alert.yaml`](https://github.com/ona-samples/github-security/blob/main/.ona/fix-codescan-alert.yaml) — fixes code scanning findings from CodeQL, Trivy, or OSV-Scanner

```bash theme={null}
ona ai automation create .ona/fix-dependabot-alert.yaml
ona ai automation create .ona/fix-codescan-alert.yaml
```

## Next steps

* [Creating Automations](/ona/automations/configure-automations) — UI-based setup
* [Automations in practice](/ona/automations/automations-in-practice) — real-world templates
* [Report step](/ona/automations/report-step) — structured data extraction
* [CLI reference](/ona/reference/cli) — full command reference
