Interview Prep/Ansible/Vault, Privilege Escalation and Error Handling

What is privilege escalation (`become`)?

BeginnerConceptVault, Privilege Escalation and Error Handling
Answer

Ansible connects as an unprivileged user and then runs the task as another user, usually root, with become. Default method is sudo. Others include su, doas, pbrun, runas (Windows), and machinectl.

- hosts: web
  become: true                 # default become_user is root
  tasks:
    - ansible.builtin.service: { name: nginx, state: restarted }
    - ansible.builtin.command: whoami
      become: true
      become_user: app          # run as another user

Set it at the narrowest scope: play, block or task. A task using become: false can override the play default.

All Ansible questions Roadmap: Ansible

More on Vault, Privilege Escalation and Error Handling