Chef infra如何删除用户?



我需要一个CHEF的recet。如何删除用户?以便在查看虚拟机列表时,没有用户。例如:

cat /etc/group|grep john.deer
john.deer:x:1043:

创建新用户,我们使用gitlab主/chef01-cookbooks/袋/用户username.json

配方:chef01-cookbooks/食谱/用户/菜谱/create_cto.rb

#service 'nslcd' do
# action [ :stop ]
#end
unless node['platform'] == 'windows'
users_manage 'fgp' do
group_id 9999
action [:create, :remove]
data_bag 'users'
end
#users_manage 'dev' do
# group_id 500
# action [:create, :remove]
# data_bag 'users'
#end

如何添加一个食谱,将删除不必要的用户。请详细描述一下,因为我最近认识了厨师。

现在在不需要的用户中chef01-cookbooks/-/树/主/袋/用户username.json

{
"id": "user.name",
"username": "john.deer",
"comment": "xxccc",
"shell":"/dev/null",
"groups": [
"fgp"
],
"action":"remove",
"ssh_keys": [
"disable"
]
}  

现在在不需要的用户中chef01-cookbooks/-/树/主/袋/用户username.json

chef-client启动后,用户就位,不被删除。虚拟机列表约500台

工作用户(需要)

{
"id": "johndo",
"username": "johndo",
"comment": "john",
"groups": [
"fgp"
],
"ssh_keys": [
"ssh-rsa AAAAB... .... ...t"
]
}

执行chef-client:

`* group[john.deer] action create (skipped due to only_if)
* linux_user[john.deer] action create (up to date)
* directory[/home/john.deer/.ssh] action create (up to date)
* template[/home/john.deer/.ssh/authorized_keys] action create (up 
to date)`
`{
"id": "john.deer",
"username": "john.deer",
"comment": "jd",
"shell":"/dev/null",
"groups": [
"fgp"
],
"action":"remove",
"ssh_keys": [
"disable"
]

} '

需要创建一个新的食谱chef01-cookbooks食谱/用户/食谱而食谱只会删除?例如,您只需要删除10个用户,不碰其余的

`#service 'nslcd' do
# action [ :stop ]
#end
unless node['platform'] == 'windows'
users_manage 'fgp' do
group_id 9999
action [:remove]
data_bag 'users'

结束

不支持使用users_manage资源的data_bag属性。您可能已经注意到chef-client运行期间出现如下警告:

Deprecated features used!
The data_bag property has been deprecated, please see upgrading.md for more information. The property will be removed in the next major release. at 1 location:

建议的替代方法是将数据包内容读入一个变量,并将其与users属性一起使用。

users_from_databag = search('users', '*:*')
users_manage 'fgp' do
group_id 9999
action [:create, :remove]
users users_from_databag
end

我在8.1.4版本的烹饪书中尝试了这种方法,它删除了标记为"action": "remove"的用户。

另一个可以一次性使用的选项是,准备一个要删除的用户列表,并删除它们。例子:

%w(
user1
user2
# and so on
).each do |u|
user u do
action :remove
end
end

最新更新