Search code examples
rubychef-infracookbook

Chef, how to set the multiple same values with different attributes?


In one local node, using chef-solo. I want set 3 value "server", but only the last value set. Please, advise, how set all values? I want to achieve, this result in settings.xml:

<servers> 
  <server> 
    <id>server1</id> 
    <username>user1</username>
     <password>pass1</password>
  </server> 
  <server>
     <id>server2</id>
     <username>user2</username>
     <password>pass2</password>
  </server> 
  <server>
     <id>server3</id> 
     <username>user3</username>
     <password>pass3</password>
  </server>
</servers>

This is my cookbook:

chef_gem 'nori' do
  action :install
end

chef_gem 'gyoku' do
  action :install
end

include_recipe "maven"
node.default['maven']['version'] = "3.3.3"

maven_settings "settings.servers" do
  value "server" => {
    "id" => "server1",
    "username" => "user1",
    "password" => "pass1"
  }
end

maven_settings "settings.servers" do
  value "server" => {
    "id" => "server2",
    "username" => "user2",
    "password" => "pass2"
  }
end

maven_settings "settings.servers" do
  value "server" => {
    "id" => "server3",
    "username" => "user3",
    "password" => "pass3"
  }
end

Thanks, foy any advise !


Solution

  • It looks like you just need to edit the servers xml attribute, so according to the maven cookbook README, the syntax should be like this:

    maven_settings "settings" do
        value "servers" => {
          "server1" => {
            "id" => "server1",
            "username" => "user1",
            "password" => "pass1"
          },
          "server2" => {
            "id" => "server2",
            "username" => "user2",
            "password" => "pass2"
          },
          "server3" => {
            "id" => "server3",
            "username" => "user3",
            "password" => "pass3"
          }   
    }
    end