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

查看:2080
本文介绍了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 用户,它没有密码,并且只能使用密钥验证登录.

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.

由于我以超级用户身份登录,因此当创建数据库用户时,当切换到 postgress 帐户时,它会要求输入密码.但是,如果从根帐户切换到 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.

注意:根帐户没有公钥,没有密码,并且无法从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天全站免登陆