Ansible asks for sudo password from following code, it tries to create a new postgres user.
Error message:
fatal: [xxx.xxx.xxx.xxx] => Missing sudo password
main.yml
- name: 'Provision a PostgreSQL server'
hosts: "dbservers"
sudo: yes
sudo_user: postgres
roles:
- postgres
create_db.yml
- name: Make sure the PostgreSQL users are present
postgresql_user: name=rails password=secret role_attr_flags=CREATEDB,NOSUPERUSER
sudo_user: postgres
sudo: yes
The remote_user that used to login to this machine is a non-root user, it has no password, and can only login using key auth.
For user postgres, this account doesn't have the password as well, because the database was just installed.
Since I logged in as non-root user, of course it will ask for password when switch to postgress account in order to create database user. But it won't be need for password if switch to postgres from root account. So, I wonder if there is a way to switch to root, and then switch to user postgres.
Note: the root account has no public key, no password, and cannot login from SSH.