Ansible如何创建用户?
导读:Ansible如何创建用户,如果想了解Ansible如何创建用户的电脑小知识,一起来了解了解吧。 Ansilbe 提供了一个 user 模块,用于创建和管理用户; 但如何在创建用户的同时加秘设置用户密码呢?
Ansible如何创建用户
如果想了解Ansible如何创建用户的电脑小知识,一起来了解了解吧。
Ansilbe 提供了一个 user 模块,用于创建和管理用户;
但如何在创建用户的同时加秘设置用户密码呢?

Ansible用户创建
- 创建一个有登录shell 的用户,用户名是 bunian1:
- name 指定创建的用户名
- shell 指定用户登录时获得的shell
- home 为用户创建 HOME 目录
- state 指定是创建还是删除用户,当 state=absent 时,为删除用户
[root@localhost ansible]# ansible redis -m user -a 'name=bunian1 shell=/bin/bash home=/home/bunian1/ state=present'
docker125 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1000,
"home": "/home/bunian1/",
"name": "bunian1",
"shell": "/bin/bash",
"state": "present",
"stderr": "useradd: warning: the home directory already exists.\nNot copying any file from skel directory into it.\n",
"stderr_lines": [
"useradd: warning: the home directory already exists.",
"Not copying any file from skel directory into it."
],
"system": false,
"uid": 1000
}
docker123 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1000,
"home": "/home/bunian1/",
"name": "bunian1",
"shell": "/bin/bash",
"state": "present",
"stderr": "useradd: warning: the home directory already exists.\nNot copying any file from skel directory into it.\n",
"stderr_lines": [
"useradd: warning: the home directory already exists.",
"Not copying any file from skel directory into it."
],
"system": false,
"uid": 1000
}
docker124 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1000,
"home": "/home/bunian1/",
"name": "bunian1",
"shell": "/bin/bash",
"state": "present",
"stderr": "useradd: warning: the home directory already exists.\nNot copying any file from skel directory into it.\n",
"stderr_lines": [
"useradd: warning: the home directory already exists.",
"Not copying any file from skel directory into it."
],
"system": false,
"uid": 1000
}
如何设置用户密码
用 ansible 设置用户的密码时,由于需要对传输的密码进行加密,所以要在主机安装python 的passlib 库。
- 利用 pip 安装 passlib:
pip install passlib - 生成的经过加密的密码(sha512 加密算法)
相关阅读
-
微软windows10下载 微软win10专业版下载地址
这些知识你了解吗?微软win10专业版下载地址的IT小经验,关于微软windows10下载 微软win10专业版下载地址,下面来一起了解一下吧。 微软win10专业版系统以其稳定性和良好的兼容性一直深受大家
-
win10锁屏密码怎么设置 win10系统怎么设置锁屏密码
IT袋网小编为你介绍win10锁屏密码怎么设置的电脑小知识,win10设置锁屏密码一共有三步,需要在账户中进行设置,以下是具体的操作步骤:
-
win7如何查看隐藏文件 win7如何查看隐藏文件?
为大家介绍win7如何查看隐藏文件方面的内容,关于win7如何查看隐藏文件 win7如何查看隐藏文件?,接下来小编为网友介绍。 win7系统是不可错过的优秀系统。最近很多的win7系统用户们都在问为什
-
win11键盘设置教程 win11轻松使用键盘默认设置
今天分享:win11键盘设置教程的相关知识,关于win11键盘设置教程 ,下面为详细的介绍。 键盘是我们在使用电脑时非常重要的外部设备,但是在最新的win11系统中,用户难免会遇到一些键盘相关


