Interview Prep/Ansible/Privilege Escalation and Python Interpreter Issues

Ansible runs, but `become_user: postgres` tasks fail with `could not change directory to "/root": Permission denied`

IntermediateTroubleshootingPrivilege Escalation and Python Interpreter Issues
Answer

Likely causes → psql runs from the login user's working directory, which the target user cannot access.

Diagnose → Run sudo -u postgres psql -c 'select 1' from /root.

Fix →

- community.postgresql.postgresql_db: { name: app }
  become: true
  become_user: postgres
  vars:
    ansible_remote_tmp: /tmp/.ansible-postgres

or use chdir: /tmp on command tasks.

Prevent → Use chdir for commands and community modules for DB work.

All Ansible questions Roadmap: Ansible

More on Privilege Escalation and Python Interpreter Issues