Ansible 中缺少 sudo 密码 [英] Missing sudo password in Ansible

查看:38
本文介绍了Ansible 中缺少 sudo 密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ansible 从以下代码中询问 sudo 密码,它尝试创建一个新的 postgres 用户.

Ansible asks for sudo password from following code, it tries to create a new postgres user.

错误信息:

致命:[xxx.xxx.xxx.xxx] => 缺少 sudo 密码

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

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

用于登录本机的remote_user是非root用户,没有密码,只能使用key auth登录.

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.

对于用户 postgres,这个帐户也没有密码,因为数据库刚刚安装.

For user postgres, this account doesn't have the password as well, because the database was just installed.

由于我以-root用户身份登录,当然在切换到postgress帐户时它会要求输入密码以创建数据库用户.但是如果从root账户切换到postgres就不需要密码了.所以,我想知道有没有办法切换到root,然后切换到用户postgres.

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.

注意:root账号没有公钥,没有密码,不能SSH登录.

Note: the root account has no public key, no password, and cannot login from SSH.

推荐答案

尝试使用选项 -kK.它会提示输入密码.

Try with the option -kK. It will prompt for password.

$ ansible-playbook mail.yml -kK 
SSH password: 
BECOME password[defaults to SSH password]: 

  • -k, --ask-pass:询问连接密码
  • -K, --ask-become-pass:请求提权密码
    • -k, --ask-pass: ask for connection password
    • -K, --ask-become-pass: ask for privilege escalation password
    • 这篇关于Ansible 中缺少 sudo 密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆