This question already has an answer here:
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
The linked glossary says:
So I think that trying the -n flag as well would at least change something since it seems like you've changed it to waiting on authentication rather than there is no authentication with your last modification.
Try to add your root user under the host.
You can try to add the line to
sudoer file
(sudo visudo)<ssh user> ALL=(ALL) NOPASSWD:ALL
and test it, maybe something is wrong there.