Chef - how to use a list of attributes in a script

后端 未结 3 1572
别跟我提以往
别跟我提以往 2020-12-22 14:00

I\'m newbie in Chef and I want to execute a script to add users in my system. I have a cookbook in chef called usersinto and attributes:

node.default[\"use         


        
3条回答
  •  感情败类
    2020-12-22 14:50

    It seems your script accepts one argument. What I can't tell if that argument is a single user in or a single string of users. If it only accepts one user, you'd need to make your node["usersinto"]["users"] attribute an array (this looks like it should be an array in any case).

    node.default["usersinto"]["users"] = %w{user1 user2 user3} 
    

    Once you have your array, iterate over it executing the bash script for each user.

    node["usersinto"]["users"].each do |user|
        bash "launch-add" do 
           code <<-EOH 
             sh /home/user/addusers.sh #{user}
           EOH 
        end
    end
    

    In the case that your script accepts multiple arguments (each argument being a different user)

    bash "launch-add" do 
       code <<-EOH 
         sh /home/user/addusers.sh #{node['usersinto']['users'].join(' ')}
       EOH 
    end
    

提交回复
热议问题