This question already has an answer here:
- How can a user with SSH keys authentication have sudo powers in Ansible? [duplicate] 1 answer
I am currently working with ansible and I want to automate dumping of my Remote DB and import the dumped file to my local DB. Now, I encountered some problem for using sudo to switch user.
playbook.yml
---
- hosts: remoteserver
vars:
remote_db_name: dbname
remote_filename: dbname_{{ lookup('pipe', 'date +%m-%d-%Y') }}
local_folder: /home/alde/database_backups/
tasks:
- name: Dump database
become: yes
become_user: postgres
shell: pg_dump -d {{remote_db_name}} > "{{remote_filename}}"
when I try to run ansible-playbook playbook.yml it returns: "sudo: a password is required"
What I have tried so far.
1) I tried this solution by adding sudo_flags.
ansible.cfg
[defaults]
sudo_flags = -H -S
then I got a different error when I execute my playbook: "Timeout (12s) waiting for privilege escalation prompt: "
2) I increased the timeout up to 30.
3) I added the default remote user to sudoers file
It's strange because there's no password prompt when I try to access my remote server using ssh and switch from default_user to postgres using sudo su - postgres
- ansible 2.3.0.0
- Python 2.7
- Ubuntu 14.04