Iván

Ansible

運維安全v1.0.0
作者:Iván更新於 2026-05-11ansible@clawhub_ivangdavila/ansible
伺服器運維DevOps

據 AlphaMoat 統計,截至 2026-09,Ansible 累計下載 3,371 次、獲 4 個星標,在全部 5,078 個 AI 技能中排名第 3,340 位,在「運維安全」分類(264 個)中排名第 214 位。

累計安裝
115
累計下載
3371
星標
4
全站排名
#3,340
全站前 66% · 「運維安全」前 82%
平台累計安裝累計下載星標評論
ClawHub ↗10333713-
SkillHub ↗11533074—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

這份參考資料彙總 YAML 引號與縮排、變數覆蓋順序、冪等任務、handler 觸發條件、條件判斷、迴圈和 facts 等常見陷阱。它也涉及 become 或 sudo 等提權選項;應用涉及許可權提升的 playbook 改動前應先審查。

資料釋出於 2026-10-29

可以用來做什麼

  • 排查 YAML 語法或縮排問題
  • 理解變數覆蓋與 handler 執行條件
  • 檢查命令任務的冪等性處理

什麼時候用

  • 編寫或審查 Ansible playbook 時
  • 排查變數、handler 或條件判斷造成的意外行為時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

檢查這段 Ansible YAML 的引號和縮排問題,並說明修正理由。
解釋這段 playbook 的變數優先順序和 handler 觸發條件;不要執行任何命令。

月度資料趨勢

累計下載3371
1728261134932026-03 · 累計下載 18502026-05 · 累計下載 24972026-06 · 累計下載 26522026-07 · 累計下載 29612026-08 · 累計下載 31952026-09 · 累計下載 337126-0326-09
星標4
3442026-03 · 星標 32026-05 · 星標 32026-06 · 星標 32026-07 · 星標 42026-08 · 星標 42026-09 · 星標 426-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-093371—4
2026-083195+7.9%4
2026-072961+11.7%4
2026-062652+6.2%3
2026-052497—3
2026-031850—3

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

3.1 KB · ClawHub v1.0.0
---
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
展開全部(共 60 行)
- 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

「運維安全」分類下的熱門技能

Iván 的其他技能

資料月份:2026-09 · 下載/星標/安裝數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。