What are common problems when becoming a non-root user?
AdvancedConceptVault, Privilege Escalation and Error Handling
Answer
When Ansible becomes an unprivileged user such as postgres, that user must be able to read the temporary module files the connecting user created. If not, you see:
Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user
Fixes, in order of preference:
- Install the
aclpackage on the target, so Ansible can usesetfaclto grant access. - Enable pipelining (
pipelining = True), so no temp file is needed. It requiresrequirettydisabled in sudoers. - As a last resort
allow_world_readable_tmpfiles = true, which has security downsides.
Also remember become_user plus sudo needs a sudoers rule allowing that user, and become_flags can set -H or -i for the right environment.
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