Pcornel
Automation · Ansible

Become

Cheat sheet · https://pcornel.dk/topic.php?topic=5412

Back to the Topic

Answer

Ansible become changes privilege context for tasks through a supported escalation method, separating connection identity from the identity under which the target action executes.

Remember

  • Connection authenticated ≠ become authorized; login and privilege escalation are separate boundaries.
  • become: true ≠ root necessarily; become_user and platform method determine effective identity.
  • Sudo command works interactively ≠ noninteractive Ansible become works with same policy.
  • Privilege escalation success ≠ task safe; authorization does not validate intended change.

First checks

  • ansible <h> -m command -a 'id' -b — become test
  • sudo -l -U <automation-user> — sudo rights on target
  • become_method/become_user — config

Verify in this order

task → become → privileged execution

Where it usually breaks

Successful become proves escalation to the configured execution context for that action; it does not prove the action itself or wider target state is correct.

Inventory/vars → play/task selection → connection/become → module request → module result → target object read-back → handler/service effective state → workload verification.

Become Ansible boundary map

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen Ansible status treated as end-to-end acceptance

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5412

Confirmation

Confirm action

Continue?