How do `block` and `become` inheritance interact?
IntermediateConceptVault, Privilege Escalation and Error Handling
Answer
Keywords on a block (become, become_user, when, vars, tags, environment, ignore_errors) apply to every task inside it, and a task's own keyword overrides the inherited one. This keeps playbooks short:
- hosts: db
tasks:
- become: true
become_user: postgres
when: pg_role == 'primary'
block:
- community.postgresql.postgresql_db: { name: app }
- community.postgresql.postgresql_user: { name: app_rw, db: app }
A when on a block is evaluated for each task in it, so values set by an earlier task can change the result partway through.
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