[chef] Re: Hosts in users databags


Chronological Thread 
  • From: Ranjib Dey < >
  • To:
  • Subject: [chef] Re: Hosts in users databags
  • Date: Tue, 9 Jul 2013 13:34:46 -0700

ssh_array << u['ssh_keys'] + ' >> ' + u['id']  if u["hosts"].include?(node.name)

btw i think you should do the filtering based on roles , instead of host names

ssh_array << (u['ssh_keys'] + ' >> ' + u['id']  ) if u["roles"].any?{|r| node.roles.include?(r)}
or
ssh_array << (u['ssh_keys'] + ' >> ' + u['id']  ) unless (u["roles"] &  node.roles).empty?


On Tue, Jul 9, 2013 at 1:13 PM, < " target="_blank"> > wrote:
Hi.

I need to improve my cookbook with use more attributes from databags. If anyone
can help me, I would appreciate it very much.

I have some structure in users databags like this:

{
  "id": "stpik",
  "ssh_keys": "ssh-rsa
AAAAB3NzaC1yc2EAAAABIwAAAQEA07GRR4vlBauJPDyEZhBg7l/YXRafbEWcH+fAa5SjKph4bJUaJiHv3WRETTTcnGElWPPQyQPBU7vQpUtcassV6gF2/EeFAeBsRReBfroNWGzqD63fFjwgS3CwewPlm5y3dhpy9vNUfPcG1ekbnPCnl66xSazBYI4j4SmCn5iGhZ8tt7tHP+IT8QVpHpVU9qUsBueSGNU68JzNmVQwH/5rh8ItFGrQfKfU3pYi7DaGP4Gj4r05jFlI+AkVwvTHg6amtjSMX2+7CRNqK2VGQrCWIaRX2PR6NEZVqBpTi/C0sdrtewU1oRhuqOV9YJnSw==
",
  "groups": ["admins"],
  "hosts": ["prod1", "prod2.example.com"]
}

and some ruby at recipe:

users = Array.new
ssh_array = Array.new

search(:ssh_users, 'groups:us') do |u|
  users << u['id']
    ssh_array << u['ssh_keys'] + ' >> ' + u['id']

template "/home/us/.ssh/authorized_keys" do
    source "authorized_keys.erb"
    owner "ess"
    group "ess"
    mode "0600"
    variables :ssh_keys => ssh_array
   end
end

The question is how I can use hosts to deliver users only to defined hosts or
if there empty then to all?




Archive powered by MHonArc 2.6.16.

§