问题描述
我有一个 ansible 任务,它在 ubuntu 12.04 上创建一个新用户;
I have an ansible task which creates a new user on ubuntu 12.04;
- name: Add deployment user
action: user name=deployer password=mypassword
它按预期完成,但是当我以该用户身份登录并尝试使用我设置的密码进行 sudo 时,它总是说它不正确.我做错了什么?
it completes as expected but when I login as that user and try to sudo with the password I set it always says it's incorrect. What am I doing wrong?
推荐答案
如果您阅读了 user
模块,它将引导您到 Ansible-examples github repo 详细了解如何使用 密码
参数.
If you read Ansible's manual for user
module, it'll direct you to the Ansible-examples github repo for details how to use password
parameter.
在那里你会看到你的密码必须经过哈希处理.
There you'll see that your password must be hashed.
- hosts: all
user: root
vars:
# created with:
# python -c 'import crypt; print crypt.crypt("This is my Password", "$1$SomeSalt$")'
password: $1$SomeSalt$UqddPX3r4kH3UL5jq5/ZI.
tasks:
- user: name=tset password={{password}}
如果您的 playbook 或 ansible 命令行的密码为纯文本,这意味着您的 shadow 文件中记录的密码哈希是错误的.这意味着当您尝试使用密码进行身份验证时,其哈希值永远不会匹配.
If your playbook or ansible command line has your password as-is in plain text, this means your password hash recorded in your shadow file is wrong. That means when you try to authenticate with your password its hash will never match.
此外,请参阅 Ansible 常见问题解答关于密码参数的一些细微差别以及如何正确使用它.
Additionally, see Ansible FAQ regarding some nuances of password parameter and how to correctly use it.
这篇关于使用 Ansible 创建新用户和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!