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.
More on Vault, Privilege Escalation and Error Handling
What is Ansible Vault?BeginnerWhich `ansible-vault` commands do you use day to day?BeginnerHow do you supply the vault password when running a playbook?BeginnerWhat is `encrypt_string` and when is it better than encrypting a whole file?IntermediateWhat are vault IDs and why use them?AdvancedHow is Vault data encrypted and what does the file look like?Advanced