Ansible
Avoid common Ansible mistakes β YAML syntax traps, variable precedence, idempotence failures, and handler gotchas.
Packaged view
This page reorganizes the original catalog entry around fit, installability, and workflow context first. The original raw source lives below.
Install command
npx @skill-hub/cli install openclaw-skills-ansible
Repository
Skill path: skills/ivangdavila/ansible
Avoid common Ansible mistakes β YAML syntax traps, variable precedence, idempotence failures, and handler gotchas.
Open repositoryBest for
Primary workflow: Ship Full Stack.
Technical facets: Full Stack.
Target audience: everyone.
License: Unknown.
Original source
Catalog source: SkillHub Club.
Repository owner: openclaw.
This is still a mirrored public skill entry. Review the repository before installing into production workflows.
What it helps with
- Install Ansible into Claude Code, Codex CLI, Gemini CLI, or OpenCode workflows
- Review https://github.com/openclaw/skills before adding Ansible to shared team environments
- Use Ansible for development workflows
Works across
Favorites: 0.
Sub-skills: 0.
Aggregator: No.
Original source / Raw SKILL.md
---
name: Ansible
description: Avoid common Ansible mistakes β YAML syntax traps, variable precedence, idempotence failures, and handler gotchas.
metadata: {"clawdbot":{"emoji":"π§","requires":{"bins":["ansible"]},"os":["linux","darwin"]}}
---
## YAML Syntax Traps
- Jinja2 in value needs quotes β `"{{ variable }}"` not `{{ variable }}`
- `:` in string needs quotes β `msg: "Note: this works"` not `msg: Note: this`
- Boolean strings: `yes`, `no`, `true`, `false` parsed as bool β quote if literal string
- Indentation must be consistent β 2 spaces standard, tabs forbidden
## Variable Precedence
- Extra vars (`-e`) override everything β highest precedence
- Host vars beat group vars β more specific wins
- `vars:` in playbook beats inventory vars β order: inventory < playbook < extra vars
- Undefined variable fails β use `{{ var | default('fallback') }}`
## Idempotence
- `command`/`shell` modules aren't idempotent β always "changed", use `creates:` or specific module
- Use `apt`, `yum`, `copy` etc. β designed for idempotence
- `changed_when: false` for commands that don't change state β like queries
- `creates:`/`removes:` for command idempotence β skips if file exists/doesn't
## Handlers
- Handlers only run if task reports changed β not on "ok"
- Handlers run once at end of play β not immediately after notify
- Multiple notifies to same handler = one run β deduplicated
- `--force-handlers` to run even on failure β or `meta: flush_handlers`
## Become (Privilege Escalation)
- `become: yes` to run as root β `become_user:` for specific user
- `become_method: sudo` is default β use `su` or `doas` if needed
- Password needed for sudo β `--ask-become-pass` or in ansible.cfg
- Some modules need become at task level β even if playbook has `become: yes`
## Conditionals
- `when:` without Jinja2 braces β `when: ansible_os_family == "Debian"` not `when: "{{ ... }}"`
- Multiple conditions use `and`/`or` β or list for implicit `and`
- `is defined`, `is not defined` for optional vars β `when: my_var is defined`
- Boolean variables: `when: my_bool` β don't compare `== true`
## Loops
- `loop:` is modern, `with_items:` is legacy β both work, loop preferred
- `loop_control.loop_var` for nested loops β avoids variable collision
- `item` is the loop variable β use `loop_control.label` for cleaner output
- `until:` for retry loops β `until: result.rc == 0 retries: 5 delay: 10`
## Facts
- `gather_facts: no` speeds up play β but can't use `ansible_*` variables
- Facts cached with `fact_caching` β persists across runs
- Custom facts in `/etc/ansible/facts.d/*.fact` β JSON or INI, available as `ansible_local`
## Common Mistakes
- `register:` captures output even on failure β check `result.rc` or `result.failed`
- `ignore_errors: yes` continues but doesn't change result β task still "failed" in register
- `delegate_to: localhost` for local commands β but `local_action` is cleaner
- Vault password for encrypted files β `--ask-vault-pass` or vault password file
- `--check` (dry run) not supported by all modules β `command`, `shell` always skip
---
## Skill Companion Files
> Additional files collected from the skill directory layout.
### _meta.json
```json
{
"owner": "ivangdavila",
"slug": "ansible",
"displayName": "Ansible",
"latest": {
"version": "1.0.0",
"publishedAt": 1770683392208,
"commit": "https://github.com/openclaw/skills/commit/79d1ad13feedc5a972c4648178e8e3a0e2fcb37a"
},
"history": []
}
```