运维自动化神器ansible之user模块

一、概述

 

user模块 可管理远程主机上的 用户,比如创建用户、修改用户、删除用户、为用户创建密钥对等操作。

二、参数介绍

 

  • name: 用于指定操作的 user必须项
  • uid: 用于指定 userUID默认为空
  • non_unique:uid参数一起使用,允许改变UID为非唯一值。
  • group: 参数用于指定用户 主组默认值,为空时创建的用户组名用户名一致。
  • groups: 参数用于指定用户属组,可以在创建用户时指定用户属组,也可以管理已经存在的用户属组。
  • append: 跟groups参数一起使用管理用户属组,默认false,如果 append='yes' ,则从groups参数中增加用户的属组;如果 append='no' ,则用户属组只设置为groups中的组,移除其他所有属组。
  • state: 参数用于指定用户是否存在远程主机中。可选值presentabsent默认值present
  • remove: 参数在 state=absent 时使用,等价于 userdel --remove 布尔类型默认值false
  • force: 参数在 state=absent 时使用,等价于 userdel --force布尔类型默认值false
  • home: 参数用于指定用户home目录,值为路径
  • create_home: 在用户创建时或home目录不存在时为用户创建home目录,布尔类型默认值true
  • move_home: 如果设置为yes,结合home= 使用,临时迁移用户家目录特定目录
  • comment: 参数用于指定用户注释信息
  • shell: 参数用于指定用户默认shell
  • system: 参数用于指定用户是否是系统用户
  • expires: 参数用于指定用户过期时间,相当于设置 /etc/shadow 文件中的的 第8列
  • passwd: 参数用于指定用户密码,但是这个密码不能明文密码,而是一个对明文密码加密后字符串默认为空
  • password_lock: 参数用于锁定指定用户,布尔类型默认为空
  • update_password: 参数可选值alwayson_create默认always

            当设置为always时,password参数的值与 /etc/shadow 中密码字符串不一致时更新用户的密码;

            当设置为on_create时,password参数的值与 /etc/shadow 中密码字符串不一致时也不会更新用户的密码,但如果是新创建的用户,则此参数即使为on_create,也会更新用户密码。
  • generate_ssh_key: 参数用于指定是否生成ssh密钥对布尔类型默认为false。当设置为yes时,为用户生成 ssh 密钥对,默认在 ~/.ssh 目录中生成名为 id_rsa私钥id_rsa.pub公钥,如果同名密钥已经存在,则不做任何操作。
  • sssh_key_bits:generate_ssh_key=yes 时,指定生成的ssh key加密位数
  • ssh_key_file:generate_ssh_key=yes 时,使用此参数指定ssh私钥的路径名称,会在同路径下生成以私钥名开头以 .pub 结尾对应公钥。
  • ssh_key_comment:generate_ssh_key=yes 时,在创建证书时,使用此参数设置公钥中的注释信息。如果同名密钥已经存在,则不做任何操作。当不指定此参数时,默认注释信息为"ansible-generated on $hostname”。
  • ssh_key_passphrase:generate_ssh_key=yes 时,在创建证书时,使用此参数设置私钥密码。如果同名密钥已经存在,则不做任何操作。
  • ssh_key_type:generate_ssh_key=yes 时,在创建证书时,使用此参数指定密钥对的类型。默认值为 rsa,如果同名密钥已经存在,则不做任何操作。

三、参数详解

 

下列英文文档部分来自于 ansible-doc,参数的修饰符号"=""-"

OPTIONS (= is mandatory):= 号开始的为必须给出的参数

3.1 name

name: 用于指定操作的 user必须项

= name
Name of the user to create, remove or modify.
(Aliases: user)
type: str

 

3.1.1 示例

使用 ansiblenote1 节点上增加 test 用户

[root@note0 ~]# ansible note1 -m user -a "name=test"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1000,
"home": "/home/test",
"name": "test",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1000
}
[root@note0 ~]#

 

验证 用户 是否 添加 成功,查看 note1 节点下的 /etc/passwd 文件

[root@note1 ~]# tail -1 /etc/passwd
test:x:1000:1000::/home/test:/bin/bash

 

3.2 uid

uid: 用于指定 userUID默认为空

- uid
Optionally sets the `UID' of the user.
[Default: (null)]
type: int
3.2.1 示例

使用 ansiblenote1 节点上增加 testuid 用户

[root@note0 ~]# ansible note1 -m user -a "name=testuid uid=2000"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 2000,
"home": "/home/testuid",
"name": "testuid",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 2000
}
[root@note0 ~]#

 

验证 用户 是否 添加 成功,查看 note1 节点下的 /etc/passwd 文件

[root@note1 ~]# tail -1 /etc/passwd
testuid:x:2000:2000::/home/testuid:/bin/bash

3.3 state

state: 参数用于指定用户是否存在远程主机中。

可选值presentabsent

默认值present,表示用户存在,相当于在远程主机创建用户;

当设置为 absent 时表示用户不存在,相当于在远程主机删除用户。

- state
Whether the account should exist or not, taking action if the state is different from what is stated.
(Choices: absent, present)[Default: present]
type: str
3.3.1 示例

使用 ansiblenote1 节点上删除 test 用户

[root@note0 ~]# ansible note1 -m user -a "name=test state=absent"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"force": false,
"name": "test",
"remove": false,
"state": "absent"
}
[root@note0 ~]#

 

验证 用户 是否 删除 成功,查看 note1 节点下是否存在 test 用户

[root@note1 ~]# id test
id: test: no such user

3.4 remove

remove: 参数在 state=absent 时使用,等价于 userdel --remove 布尔类型,默认值false

- remove
This only affects `state=absent', it attempts to remove directories associated with the user.
The behavior is the same as `userdel --remove', check the man page for details and support.
[Default: False]
type: bool
3.4.1 示例1

示例3.3.1 中我们已经使用 ansiblenote1 节点上删除了 test 用户,现在让我们查看test用户home目录是否存在。

[root@note1 ~]# cd /home
#查看home目录
[root@note1 home]# ll
总用量 0
drwx------ 2 1000 1000 59 7月 9 16:41 test
drwx------ 2 testuid testuid 59 7月 9 17:01 testuid
[root@note1 home]#

我们可以看到,通过state=absent删除的用户home目录还存在,下面我们来演示一下彻底删除一个用户。

3.4.2 示例2

使用 ansiblenote1 节点上删除 testuid 用户

[root@note0 ~]# ansible note1 -m user -a "name=testuid state=absent remove=yes"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"force": false,
"name": "testuid",
"remove": true,
"state": "absent"
}
[root@note0 ~]#

 

下面我们来验证一下,用户home目录是否彻底删除

#查看testuid用户是否存在
[root@note1 home]# id testuid
id: testuid: no such user
#查看home目录
[root@note1 home]# ll
总用量 0
drwx------ 2 1000 1000 59 7月 9 16:41 test
[root@note1 home]#

3.5 group

group: 参数用于指定用户 主组默认值,创建的用户组名用户名一致。

- group
Optionally sets the user's primary group (takes a group name).
[Default: (null)]
type: str
3.5.1 示例

使用 ansiblenote1 节点上 创建test 用户,并指定主组为 testgrp

#首先创建使用ansible创建testgrp组
[root@note0 ~]# ansible note1 -m group -a "name=testgrp state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 1000,
"name": "testgrp",
"state": "present",
"system": false
}
#使用ansible创建test用户
[root@note0 ~]# ansible note1 -m user -a "name=test group=testgrp state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1000,
"home": "/home/test",
"name": "test",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1000
}
[root@note0 ~]#

 

验证 用户 是否 创建 成功

[root@note1 home]# id test
uid=1000(test) gid=1000(testgrp) 组=1000(testgrp)

3.6 groups、append

groups: 参数用于指定用户属组,可以在创建用户时指定用户属组,也可以管理已经存在的用户属组。

groups列表类型,多个参数以逗号分隔,例如 groups='grp,mygrp'默认值 ,也可以设置空字符串 groups=''groups=`null`groups=`~` ,将用户从其他属组 移除

append: 跟groups参数一起使用管理用户属组。布尔类型,默认为false,如果 append='yes' ,则从groups参数中增加用户的属组;如果 append='no' ,则用户属组只设置为groups中的组,移除其他所有属组。

- groups
List of groups user will be added to. When set to an empty string `''', `null', or `~', the user is removed from all groups
except the primary group. (`~' means `null' in YAML)
Before Ansible 2.3, the only input format allowed was a comma separated string.
[Default: (null)]
type: list - append
If `yes', add the user to the groups specified in `groups'.
If `no', user will only be added to the groups specified in `groups', removing them from all other groups.
[Default: False]
type: bool
3.6.1 示例1-创建用户时指定属组

先使用 ansiblenote1 节点上创建 mygrp1mygrp2mygrp3 测试组

#首先创建使用创建测试组
[root@note0 ~]# ansible note1 -m group -a "name=mygrp1 gid=2001 state=present"
[root@note0 ~]# ansible note1 -m group -a "name=mygrp2 gid=2002 state=present"
[root@note0 ~]# ansible note1 -m group -a "name=mygrp3 gid=2003 state=present" #测试组创建成功
[root@note1 home]# cat /etc/group
mygrp1:x:2001:
mygrp2:x:2002:
mygrp3:x:2003:

 

创建用户 testuser,并指定属组为 mygrp1 mygrp2

[root@note0 ~]# ansible note1 -m user -a "name=testuser groups=mygrp1,mygrp2 state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1001,
"groups": "mygrp1,mygrp2",
"home": "/home/testuser",
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
[root@note0 ~]#

 

验证用户 testuser属组mygrp1mygrp2

[root@note1 home]# id testuser
uid=1001(testuser) gid=1001(testuser) 组=1001(testuser),2001(mygrp1),2002(mygrp2)
3.6.2 示例2-已创建用户增加属组

testuser属组变更为mygrp1mygrp2mygrp3

3.6.2.1 不使用append,使用groups指明用户的所有属组即可
[root@note0 ~]# ansible note1 -m user -a "name=testuser groups='mygrp1,mygrp2,mygrp3' state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": false,
"changed": true,
"comment": "",
"group": 1001,
"groups": "mygrp1,mygrp2,mygrp3",
"home": "/home/testuser",
"move_home": false,
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
[root@note0 ~]#

 

验证用户testuser属组是否为mygrp1mygrp2mygrp3

[root@note1 home]# id testuser
uid=1001(testuser) gid=1001(testuser) 组=1001(testuser),2001(mygrp1),2002(mygrp2),2003(mygrp3)
3.6.2.2 使用append属性

先将testuser用户属组还原为mygrp1mygrp2

增加属组mygrp3

#使用append=yes时,只将要添加的属组填入groups参数中即可。
[root@note0 ~]# ansible note1 -m user -a "name=testuser groups='mygrp3' append=yes state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": true,
"changed": true,
"comment": "",
"group": 1001,
"groups": "mygrp3",
"home": "/home/testuser",
"move_home": false,
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
[root@note0 ~]#

 

验证用户testuser属组是否为mygrp1mygrp2mygrp3

[root@note1 home]# id testuser
uid=1001(testuser) gid=1001(testuser) 组=1001(testuser),2001(mygrp1),2002(mygrp2),2003(mygrp3)
3.6.3 示例3-已创建用户移除属组

testuser属组变更为mygrp1

3.6.3.1 不使用append,使用groups指明用户的所有属组即可
[root@note0 ~]# ansible note1 -m user -a "name=testuser groups='mygrp1' state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": false,
"changed": true,
"comment": "",
"group": 1001,
"groups": "mygrp1",
"home": "/home/testuser",
"move_home": false,
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
[root@note0 ~]#

 

验证用户testuser属组是否为mygrp1

[root@note1 home]# id testuser
uid=1001(testuser) gid=1001(testuser) 组=1001(testuser),2001(mygrp1)
3.6.3.2 使用append属性

先将testuser用户属组还原为mygrp1mygrp2mygrp3

变更用户testuser属组为mygrp3

#使用append=no时,用户的属组只设置为groups参数中的组
[root@note0 ~]# ansible note1 -m user -a "name=testuser groups='mygrp1' append='no' state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": false,
"changed": true,
"comment": "",
"group": 1001,
"groups": "mygrp1",
"home": "/home/testuser",
"move_home": false,
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
[root@note0 ~]#

 

验证用户testuser属组是否为mygrp1

[root@note1 home]# id testuser
uid=1001(testuser) gid=1001(testuser) 组=1001(testuser),2001(mygrp1)

3.7 passwd

passwd: 参数用于指定用户密码,但是这个密码不能明文密码,而是一个对明文密码加密后字符串,相当于 /etc/shadow 文件中的密码字段,是一个对明文密码进行哈希后的字符串,可以使用命令生成明文密码对应的加密字符串

- password
Optionally set the user's password to this crypted value.
On macOS systems, this value has to be cleartext. Beware of security issues.
To create a disabled account on Linux systems, set this to `'!'' or `'*''.
See https://docs.ansible.com/ansible/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module for details on various
ways to generate these password values.
[Default: (null)]
type: str

 

要生成md5算法的密码,使用openssl即可。

openssl passwd -1 '123456'
openssl passwd -1 -salt 'abcdefg' '123456'

 

openssl passwd 不支持生成sha-256sha-512算法的密码。使用python命令生成sha-512算法

python -c 'import crypt,getpass;pw="123456";print(crypt.crypt(pw))'

 

现在就方便多了,直接将结果赋值变量即可。

[root@note0 ~]# a=$(python -c 'import crypt,getpass;pw="123456";print(crypt.crypt(pw))')
[root@note0 ~]# echo $a
$6$uKhnBg5A4/jC8KaU$scXof3ZwtYWl/6ckD4GFOpsQa8eDu6RDbHdlFcRLd/2cDv5xYe8hzw5ekYCV5L2gLBBSfZ.Uc166nz6TLchlp.

 

例如,ansible创建用户并指定密码:

[root@note0 ~]# a=$(python -c 'import crypt,getpass;pw="123456";print(crypt.crypt(pw))')
[root@note0 ~]# ansible note1 -m user -a 'name=testpass password="$a" update_password=always'
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly. 176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1005,
"home": "/home/testpass",
"name": "testpass",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1005
}
[root@note0 ~]#

 

登录验证

[root@note0 ~]# ssh testpass@note1
testpass@note1's password:
Last login: Thu Jul 11 00:12:57 2019 from note0
[testpass@note1 ~]$ who am i
testpass pts/1 2019-07-11 00:13 (note0)
[testpass@note1 ~]$

3.8 expires

expires: 参数用于指定用户过期时间,相当于设置 /etc/shadow 文件中的的 第8列 ,比如,你想要设置用户的过期日期为2019年07月10日,那么你首先要获取2019年07月10日的 unix 时间戳,使用命令 date -d 20190710 +%s 获取到的时间戳1562688000,所以,当设置 expires=1562688000 时,表示用户的过期时间2019年07月10日0点0分,设置成功后,查看远程主机的 /etc/shadow 文件,对应用户的第8列的值将变成18086(表示1970年1月1日到2019年07月10日的天数,unix 时间戳的值会自动转换为天数,我们不用手动的进行换算),当前ansible版本此参数支持在GNU/Linux, FreeBSD, and DragonFlyBSD 系统中使用。

3.8.1 示例

设置一个过期时间20190710的用户testexprie

[root@note0 ~]# ansible note1 -m user -a "name=testexpire expires=1562688000 comment='expires date is 20190710' state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "expires date is 20190710",
"create_home": true,
"group": 1003,
"home": "/home/testexpire",
"name": "testexpire",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1003
}
[root@note0 ~]#

 

note1上验证testexprie用户

[root@note1 home]# cat /etc/shadow
testexpire:!!:18086:0:99999:7::18086:

登录失败,提示账号过期

[root@note0 ~]# ssh testexpire@note1
testexpire@note1's password:
Your account has expired; please contact your system administrator
Connection closed by 176.16.128.1

3.9 home

home: 参数用于指定用户home目录,值为路径

- home
Optionally set the user's home directory.
[Default: (null)]
type: path - create_home
Unless set to `no', a home directory will be made for the user when the account is created or if the home directory does not
exist.
Changed from `createhome' to `create_home' in Ansible 2.5.
(Aliases: createhome)[Default: True]
type: bool - move_home
If set to `yes' when used with `home: ', attempt to move the user's old home directory to the specified directory if it isn't
there already and the old home exists.
[Default: False]
type: bool
3.9.1 示例
[root@note0 ~]# ansible note1 -m user -a "name=testhome home=/home/testdir state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1004,
"home": "/home/testdir",
"name": "testhome",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1004
}
[root@note0 ~]#

 

验证testhome用户的home目录

# 首先登录note1节点,su到testhome用户
[root@note1 ~]# su - testhome
# cd 到主目录
[testhome@note1 ~]$ cd ~
# 执行pwd
[testhome@note1 ~]$ pwd
/home/testdir
[testhome@note1 ~]$

3.10 move_home

move_home: 如果设置为yes,结合home= 使用,临时迁移用户家目录特定目录

- move_home
If set to `yes' when used with `home: ', attempt to move the user's old home directory to the specified directory if it isn't
there already and the old home exists.
[Default: False]
type: bool
3.10.1 示例

首先创建testmove用户,然后在testmove用户home目录下创建test_move_home.txt文件

#创建testmove用户。
[root@note0 ~]# ansible note1 -m user -a "name=testmove state=present"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1006,
"home": "/home/testmove",
"name": "testmove",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1006
}
#使用ansible的file模块在testmove用户home目录下创建test_move_home.txt文件
[root@note0 ~]# ansible note1 -m file -a "path=/home/testmove/test_move_home.txt state=touch"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/home/testmove/test_move_home.txt",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
} #在note1节点上,查看/home/testmove下是否存在test_move_home.txt
[root@note1 ~]# cd /home/testmove
[root@note1 testmove]# ll
总用量 0
-rw-r--r-- 1 root root 0 7月 11 06:22 test_move_home.txt
[root@note1 testmove]#

使用ansible的move_home参数迁移用户home目录

#迁移testmove用户的home目录至/tmp/testmove_new
[root@note0 ~]# ansible note1 -m user -a "user=testmove move_home=yes home=/tmp/testmove_new/"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": false,
"changed": true,
"comment": "",
"group": 1006,
"home": "/tmp/testmove_new/",
"move_home": true,
"name": "testmove",
"shell": "/bin/bash",
"state": "present",
"uid": 1006
}
[root@note0 ~]#

验证迁移的新home目录下是否存在test_move_home.txt文件

[root@note1 testmove]# cd /tmp/testmove_new/
[root@note1 testmove_new]# ll
总用量 0
-rw-r--r-- 1 root root 0 7月 11 06:22 test_move_home.txt
[root@note1 testmove_new]#

3.11 generate_ssh_key

generate_ssh_key: 参数用于指定是否生成ssh密钥对布尔类型默认为false。当设置为yes时,为用户生成 ssh 密钥对,默认在 ~/.ssh 目录中生成名为 id_rsa私钥id_rsa.pub公钥,如果同名密钥已经存在,则不做任何操作。

- generate_ssh_key
Whether to generate a SSH key for the user in question.
This will *not* overwrite an existing SSH key unless used with `force=yes'.
[Default: False]
type: bool
version_added: 0.9
3.11.1 示例

使用ansible创建testssh用户,并生成ssh_key。

[root@note0 ~]# ansible note1 -m user -a "name=testssh state=present generate_ssh_key=yes"
176.16.128.1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1007,
"home": "/home/testssh",
"name": "testssh",
"shell": "/bin/bash",
"ssh_fingerprint": "2048 07:18:48:ea:f1:dc:95:22:75:fc:b5:5e:80:25:a7:1f ansible-generated on note1 (RSA)",
"ssh_key_file": "/home/testssh/.ssh/id_rsa",
"ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIrQCOP11FK/s50vpOm/z+hXEmet+oEdWqGbyQD0JdN0AJrS/MzHZF3v+sjMf4SoDL7PafPYnFY4iVEtNOuBK8uvQgziVXVRxPs7h9Yy+ZdFw8qFjeiC74pKl+0Mqq49I9TD1GMbOQRd0K7nTycymCAX0MW5lQz7q44f3qa4+4y8C63xxi/4H9x3lJ+JsjDDIzKo4i69CnqU3Bn+0HzfxYi9j63HtcdLF8OwVfyF73lK6xd+vK68AaxRfPIOEj4KJXU3iMdiM5zVvMZgjEKyaGKPJD/uQl35MV2oazmFHTHWrKgA5AXwJEMKJYJzF6a8Z6SrmSnvxp6TpnMmbXAjev ansible-generated on note1",
"state": "present",
"system": false,
"uid": 1007
}
[root@note0 ~]#

验证note1节点下的ssh_key文件

[root@note1 ~]# cd /home/testssh/.ssh
[root@note1 .ssh]# ll
总用量 8
-rw------- 1 testssh testssh 1679 7月 11 06:39 id_rsa
-rw-r--r-- 1 testssh testssh 408 7月 11 06:39 id_rsa.pub
[root@note1 .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIrQCOP11FK/s50vpOm/z+hXEmet+oEdWqGbyQD0JdN0AJrS/MzHZF3v+sjMf4SoDL7PafPYnFY4iVEtNOuBK8uvQgziVXVRxPs7h9Yy+ZdFw8qFjeiC74pKl+0Mqq49I9TD1GMbOQRd0K7nTycymCAX0MW5lQz7q44f3qa4+4y8C63xxi/4H9x3lJ+JsjDDIzKo4i69CnqU3Bn+0HzfxYi9j63HtcdLF8OwVfyF73lK6xd+vK68AaxRfPIOEj4KJXU3iMdiM5zVvMZgjEKyaGKPJD/uQl35MV2oazmFHTHWrKgA5AXwJEMKJYJzF6a8Z6SrmSnvxp6TpnMmbXAjev ansible-generated on note1
[root@note1 .ssh]#

 

ansible的user模块常用参数就介绍到这里,不做过多赘述了。欢迎指点交流。

运维自动化神器ansible之user模块的更多相关文章

  1. 运维自动化神器ansible之group模块

    ansible之group模块 group模块是用来添加或者删除组 首先使用ansible-doc来查看用法 [root@note0 ansible]# ansible-doc -s group - ...

  2. Ansible运维自动化工具19个常用模块使用实例【转】

    一.模块列表 1.setup 2.ping 3.file 4.copy 5.command 6.shell 7.script 8.cron 9.yum 10.service 11.group 12.u ...

  3. 运维自动化之ansible的安装与使用 转

    运维自动化之ansible的安装与使用 随着服务器数量的增长,我们需要一个批量工具去提高工作效率,之前用的是puppet,ansible的简单,适用让我眼前一亮,决定写一篇ansible从安装到基本配 ...

  4. 运维自动化工具ansible

    企业级自动化运维工具应用实战ansible 公司计划在年底做一次大型市场促销活动,全面冲刺下交易额,为明年的上市做准备.公司要求各业务组对年底大促做准备,运维部要求所有业务容量进行三倍的扩容,并搭建出 ...

  5. 运维自动化之ansible的安装与使用(包括模块与playbook使用)(转发)

    原文  http://dl528888.blog.51cto.com/2382721/1435415 我使用过puppet(地址是http://dl528888.blog.51cto.com/2382 ...

  6. 运维自动化之ansible

    Ansible简介 Ansible是一个简单的自动化运维管理工具,基于Python语言实现,由Paramiko和PyYAML两个关键模块构建,可用于自动化部署应用.配置.编排task(持续交付.无宕机 ...

  7. 自动化运维工具之 Ansible 介绍及安装使用

    一.初识Ansible 介绍: Absible 使用 模块(Modules)来定义配置任务.模块可以用标准脚本语言(Python,Bash,Ruby,等等)编写,这是一个很好的做法,使每个模块幂等.A ...

  8. 自动化运维工具之ansible

    自动化运维工具之ansible   一,ansible简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fab ...

  9. Ansible 运维自动化 ( 配置管理工具 )

    背景 出差背景,要搞项目的自动化部署.因为只直接对接生产分发,机器又非常多,这样以往使用的bat只能作为应急方案了,还是得考虑使用专业化的工具来做这个事情! 当下有许多的运维自动化工具( 配置管理 ) ...

随机推荐

  1. 题解 洛谷P5259【欧稳欧再次学车】

    实际上没什么可说的,暴力大模拟就好. 一定要开long long! 一定要开long long! 一定要开long long! (不然会炸数据的!!!) //Stand up for the fait ...

  2. Storm VS Flink ——性能对比

    1.背景 Apache Flink 和 Apache Storm 是当前业界广泛使用的两个分布式实时计算框架.其中 Apache Storm(以下简称"Storm")在美团点评实时 ...

  3. Python 之父的解析器系列之六:给 PEG 语法添加动作

    原题 | Adding Actions to a PEG Grammar 作者 | Guido van Rossum(Python之父) 译者 | 豌豆花下猫("Python猫"公 ...

  4. oracle用imp导入dmp文件

    oracle命令行登录 sqlplus 用户名/密码 创建用户 create user 用户 identified by 密码 ; 创建表空间 create tablespace 表空间名 dataf ...

  5. Spring boot运行原理-自定义自动配置类

    在前面SpringBoot的文章中介绍了SpringBoot的基本配置,今天我们将给大家讲一讲SpringBoot的运行原理,然后根据原理我们自定义一个starter pom. 本章对于后续继续学习S ...

  6. 【学习笔记】第二章 python安全编程基础---正则表达式

    一.python正则表达式 定义:正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式相匹配: 1.1RE模块:是python语言拥有全部的正则表达式功能的一个正则模块: 常见 ...

  7. centos7 下安装mysql5.7 数据库并使用nevicat连接数据库

    安装mysql5.7的教程: https://www.cnblogs.com/yybrhr/p/9810375.html 遇到的问题: 无法连接,到阿里云服务器安全组设置3306端口

  8. 一文搞懂 deconvolution、transposed convolution、sub-­pixel or fractional convolution

    目录 写在前面 什么是deconvolution convolution过程 transposed convolution过程 transposed convolution的计算 整除的情况 不整除的 ...

  9. iOS 13 正式发布,来看看有哪些 API 变动

    iOS 13 已正式发布,网上对其用户体验上的新特性的描述也很多.对于开发来说,需要关注的另一方面是新系统在 API 层面做了哪些改动,从而会对我们现有的代码产生什么影响. 在这里,我们基于 iOS ...

  10. java8 新特性精心整理

    前言 越来越多的项目已经使用 Java 8 了,毫无疑问,Java 8 是Java自Java 5(发布于2004年)之后的最重要的版本.这个版本包含语言.编译器.库.工具和 JVM 等方面的十多个新特 ...