使用厨师客户端创建功能13.4.19

时间:2017-10-31 10:56:29

标签: chef chef-recipe chef-solo

我们需要创建20个用户并将这些用户(不是所有用户)添加到所需的服务器。如何使用厨师配方完成此操作。厨师13.4.19不支持定义。

Server1: - a,b,c Server2: - b,d,e server3: - f,g,h

注意: - a到h表示用户。

单用户食谱

user "xxxxx" do
  manage_home  true
  comment "admin"
  uid 10001
  gid "yyyyyyy"
  shell "/bin/bash"
  home "/home/xxxxx"
end
directory "/home/xxxxx/.ssh" do
   owner "xxxxx"
   group "xxxxx"
   mode "0700"
end
file "/home/xxxxx/.ssh/authorized_keys" do
   #source "authorized_keys_xxxxx"
   content 'ssh-rsa AAAAB3Nsldjflsjdflhsdjflsldflsjdf5KksjfxvmzbcmzxbcmzxbcsjdjshdkjsweyriewyiyweifhskdjhfisdfksdjhfisdhfkjsbvmxcvksdfhksdncksdhfkjxchvisdhfsdkvcyisdhvksdhcvisdhcisdfwieyirweuyriweyriwueyriweuhkcxvbbcvkxbcvksxviusdyfisdfyiCHrtfF5BX936vhPSrwgSbGJ48DKIxquib5ZYrjK9KyUNNrrg19wl5TW xxxxx_rsa.pub@Macbook-pro'
   owner "xxxxx"
   group "xxxxx"
   mode "0600"
end

感谢和问候

1 个答案:

答案 0 :(得分:0)

您通常希望制作一个custom resource来描述用户的所有内容,然后可能是这样的一些食谱代码:

my_user 'a' do
  uid 1234
  ssh_key 'whatever'
  # Other stuff here
  only_if { %w{server1.example.com server2.example.com}.include?(node['fqdn']) }
end

或类似的东西,您也可以使用条件操作而不是only_if