The Core Ansible Workflow
Lint, dry-run with check and diff, try one host, run in batches, and read the recap, plus the options DBAs use most.
The core workflow
Like Terraform, Ansible has a short, safe cycle for every change: check the playbook, preview what it would change with a dry run, try it on one server, then run it everywhere it's meant to go, and read the recap. The dry run is Ansible's equivalent of terraform plan.
1. Check the playbook
$ ansible-playbook prepare_oracle.yml --syntax-check
playbook: prepare_oracle.yml
$ ansible-lint prepare_oracle.yml
Passed: 0 failure(s), 0 warning(s) on 1 files.
- What it does
--syntax-checkconfirms the YAML and playbook structure are valid, without connecting to any server. ansible-lint goes further, flagging bad practices: short module names instead of full ones,shellwhere a module exists, tasks without names, and commands that aren't safe to repeat.- When to run it
- On every change, and as the first step of the pipeline for every pull request.
2. Preview the changes
$ ansible-playbook -i inventory prepare_oracle.yml --check --diff
TASK [Create Oracle directories, owned by oracle] **************
--- before
+++ after
@@ -1,4 +1,4 @@
{
"path": "/u02/oradata",
- "state": "absent"
+ "state": "directory"
}
changed: [db02.acme.local] => (item=/u02/oradata)
PLAY RECAP *****************************************************
db01.acme.local : ok=4 changed=0 unreachable=0 failed=0
db02.acme.local : ok=4 changed=1 unreachable=0 failed=0
- What it does
- Check mode (
--check) runs the playbook without changing anything: each task reports what it would do.--diffshows the exact before and after for files and settings. Together they're Ansible's dry run. - Its limits
- Tasks that depend on earlier changes, and
commandorshelltasks, can't be fully predicted, and are skipped or reported as unknown in check mode. Treat the dry run as a strong preview, not a guarantee.
3. Try it on one server
$ ansible-playbook -i inventory prepare_oracle.yml --limit db03.acme.local
--limit restricts a run to some of the targets, here a single test server. If it goes well there, widen it: --limit test, then everything. It's also the quickest way to rerun a playbook only on servers that failed last time.
4. Run it everywhere
$ ansible-playbook -i inventory prepare_oracle.yml
For changes that could disrupt service, run in batches rather than everywhere at once. In the playbook:
- name: Apply OS settings to production database servers
hosts: oracle:&prod
become: true
serial: 2 # two servers at a time
max_fail_percentage: 0 # stop everything if any server fails
tasks:
...
With serial, Ansible finishes the whole play on each batch before starting the next, so a problem stops the rollout after a couple of servers instead of all of them.
5. Read the recap
The PLAY RECAP at the end summarizes each server: how many tasks were ok, changed, failed, skipped, or unreachable. Check it every time: an unexpected changed on a server that should already be right means someone has changed it by hand, which is drift. Running the playbook again straight away should show changed=0 everywhere, which proves it's idempotent.
Other useful options
| Option | What it does |
|---|---|
--tags, --skip-tags | Run only, or skip, tasks with given tags, such as --tags kernel |
--start-at-task "name" | Resume from a given task after fixing a failure |
--step | Ask for confirmation before each task |
-v, -vvv | More detail, for troubleshooting |
-e "var=value" | Set a variable on the command line, such as -e target_ru=19.28 |
--list-hosts | Show which servers would be targeted, without running anything |
Key takeaways
- Check every playbook with
--syntax-checkandansible-lint. - Dry-run with
--check --diffto see what would change; it's a strong preview, not a guarantee. - Try changes on one server with
--limit, then widen. - Roll out in batches with
serialand stop on failures withmax_fail_percentage. - Read the PLAY RECAP every time; a second run should show
changed=0. - Use
--list-hostsbefore touching production.