How to append an variable using chef

Hi All,

I need to set an attribute variable through chef recipe.

I an using a role file where I have defined weblogic cluster information
like

“wls_cluster”: {
“oci_cluster1”: {
“managed_servers”: {
“oci_man1”: {
“ip_address”: “10.10.10.31”,
“listen_port”: “7101”
},
“oci_man2”: {
“ip_address”: “10.10.10.32”,
“listen_port”: “7101”
}
}
},

my weblogic oci_cluster1 can have any number of managed servers, is this
example there are two

In my chef recipe i am using this code to fetch run time managed servers
information

    node[:ohs][:wls_cluster].each do |cluster, cluster_attrib|
       cluster_attrib.managed_servers.each do |managed_server,

man_attrib|
Chef::Log.info "the IP address is #{man_attrib.ip_address} and
port is #{man_attrib.listen_port}"
node.set[:ohs][:wls_cluster] = "#{man_host}:#{man_port},"
Chef::Log.info "the value of wls_cluster are
#{node[:ohs][:wls_cluster]}"
end
end

I have an attribute variable default[:ohs][:wls_cluster] =’’ initially set
to null, I want to set this variable through chef recipe something like

[:ohs][:wls_cluster]=
“ip_address:listen_port,ip_address:listen_port,ip_address:listen_port…”

can anyone help how to append the variable values using chef.

Thanks & Regards,
Sachin Gupta

Try,

knife exec -E ‘nodes.find(:name => some_node) {|n| n.set.ohs.wls_cluster = “ip_address : listen_port” ; n.save }’

Chris

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Monday, June 08, 2015 6:38 AM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] how to append an variable using chef

Hi All,

I need to set an attribute variable through chef recipe.

I an using a role file where I have defined weblogic cluster information like

“wls_cluster”: {
“oci_cluster1”: {
“managed_servers”: {
“oci_man1”: {
“ip_address”: “10.10.10.31”,
“listen_port”: “7101”
},
“oci_man2”: {
“ip_address”: “10.10.10.32”,
“listen_port”: “7101”
}
}
},

my weblogic oci_cluster1 can have any number of managed servers, is this example there are two

In my chef recipe i am using this code to fetch run time managed servers information

    node[:ohs][:wls_cluster].each do |cluster, cluster_attrib|
       cluster_attrib.managed_servers.each do |managed_server, man_attrib|
        Chef::Log.info "the IP address  is #{man_attrib.ip_address} and port is #{man_attrib.listen_port}"
        node.set[:ohs][:wls_cluster] = "#{man_host}:#{man_port},"
        Chef::Log.info "the value of wls_cluster are #{node[:ohs][:wls_cluster]}"
       end
    end

I have an attribute variable default[:ohs][:wls_cluster] =’’ initially set to null, I want to set this variable through chef recipe something like

[:ohs][:wls_cluster]= “ip_address:listen_port,ip_address:listen_port,ip_address:listen_port…”

can anyone help how to append the variable values using chef.

Thanks & Regards,
Sachin Gupta

Hi Chris,

I am using chef-solo for my development. I don’t think chef-solo supports
Search indexes.

I am using a temp file to write the cluster configuration like

execute “Setting cluster configuration” do
command "echo -n
#{man_attrib.ip_address}:#{man_attrib.listen_port}, >> /tmp/wls_cluster"
end

Is this the right approach??

Thanks
Sachin

On Mon, Jun 8, 2015 at 7:04 PM, Fouts, Chris Chris.Fouts@sensus.com wrote:

Try,

knife exec -E ‘nodes.find(:name => some_node) {|n| n.set.ohs.wls_cluster =
“ip_address : listen_port” ; n.save }’

Chris

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Monday, June 08, 2015 6:38 AM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] how to append an variable using chef

Hi All,

I need to set an attribute variable through chef recipe.

I an using a role file where I have defined weblogic cluster information
like

“wls_cluster”: {
“oci_cluster1”: {
“managed_servers”: {
“oci_man1”: {
“ip_address”: “10.10.10.31”,
“listen_port”: “7101”
},
“oci_man2”: {
“ip_address”: “10.10.10.32”,
“listen_port”: “7101”
}
}
},

my weblogic oci_cluster1 can have any number of managed servers, is this
example there are two

In my chef recipe i am using this code to fetch run time managed servers
information

    node[:ohs][:wls_cluster].each do |cluster, cluster_attrib|
       cluster_attrib.managed_servers.each do |managed_server,

man_attrib|
Chef::Log.info "the IP address is #{man_attrib.ip_address}
and port is #{man_attrib.listen_port}"
node.set[:ohs][:wls_cluster] = "#{man_host}:#{man_port},"
Chef::Log.info "the value of wls_cluster are
#{node[:ohs][:wls_cluster]}"
end
end

I have an attribute variable default[:ohs][:wls_cluster] =’’ initially set
to null, I want to set this variable through chef recipe something like

[:ohs][:wls_cluster]=
“ip_address:listen_port,ip_address:listen_port,ip_address:listen_port…”

can anyone help how to append the variable values using chef.

Thanks & Regards,

Sachin Gupta

On Tuesday, June 9, 2015 at 3:11 AM, Sachin Gupta wrote:

Hi Chris,

I am using chef-solo for my development. I don’t think chef-solo supports Search indexes.

I am using a temp file to write the cluster configuration like

execute “Setting cluster configuration” do
command "echo -n #{man_attrib.ip_address}:#{man_attrib.listen_port}, >> /tmp/wls_cluster"
end

Is this the right approach??
It’s always better to manage the whole resource if you can. If you generated that file from a template earlier, it would be preferable to merge the data you pass in to the template instead of appending to it like this.

If you have no other option, then you should take care to ensure that this won’t keep appending every time you run chef.

Thanks
Sachin


Daniel DeLeo

On Mon, Jun 8, 2015 at 7:04 PM, Fouts, Chris <Chris.Fouts@sensus.com (mailto:Chris.Fouts@sensus.com)> wrote:

Try,

knife exec -E ‘nodes.find(:name => some_node) {|n| n.set.ohs.wls_cluster = “ip_address : listen_port” ; n.save }’

Chris

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Monday, June 08, 2015 6:38 AM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Cc: sachin kumar
Subject: [chef] how to append an variable using chef

Hi All,

I need to set an attribute variable through chef recipe.

I an using a role file where I have defined weblogic cluster information like

“wls_cluster”: {
“oci_cluster1”: {
“managed_servers”: {
“oci_man1”: {
“ip_address”: “10.10.10.31”,
“listen_port”: “7101”
},
“oci_man2”: {
“ip_address”: “10.10.10.32”,
“listen_port”: “7101”
}
}
},

my weblogic oci_cluster1 can have any number of managed servers, is this example there are two

In my chef recipe i am using this code to fetch run time managed servers information

node[:ohs][:wls_cluster].each do |cluster, cluster_attrib|
cluster_attrib.managed_servers.each do |managed_server, man_attrib|
Chef::Log.info (http://Log.info) "the IP address is #{man_attrib.ip_address} and port is #{man_attrib.listen_port}"
node.set[:ohs][:wls_cluster] = "#{man_host}:#{man_port},"
Chef::Log.info (http://Log.info) "the value of wls_cluster are #{node[:ohs][:wls_cluster]}"
end
end

I have an attribute variable default[:ohs][:wls_cluster] =’’ initially set to null, I want to set this variable through chef recipe something like

[:ohs][:wls_cluster]= “ip_address:listen_port,ip_address:listen_port,ip_address:listen_port…”

can anyone help how to append the variable values using chef.

Thanks & Regards,
Sachin Gupta

Hi Daniel/Chris,

I followed a simple approach to define an array and pushing the values in
appropriate format in that array and then finally setting the attribute
through an arrray like

wls_servers = Array.new

node[:oci_ohs][:wls_cluster].each do |cluster, cluster_attrib|
cluster_attrib.managed_servers.each do |managed_server, man_attrib|
Chef::Log.info "the IP address is #{man_attrib.ip_address} and
port is #{man_attrib.listen_port}"
wls_servers << "#{man_attrib.ip_address}:#{man_attrib.listen_port}"
end
end

node.set[:oci_ohs][:wls_cluster_detail] = wls_servers.join(",")
Chef::Log.info “the WLS Cluster Information are
#{node[:oci_ohs][:wls_cluster_detail]}”

Now I am able to get the weblogic cluster information like, I need this
information to define in mod_wl_ohs.conf
WebLogicCluster 10.152.173.31:7101,10.152.173.31:7101,10.152.173.31:7101

Thanks
Sachin

On Wed, Jun 10, 2015 at 2:58 AM, Daniel DeLeo dan@kallistec.com wrote:

On Tuesday, June 9, 2015 at 3:11 AM, Sachin Gupta wrote:

Hi Chris,

I am using chef-solo for my development. I don’t think chef-solo
supports Search indexes.

I am using a temp file to write the cluster configuration like

execute “Setting cluster configuration” do
command "echo -n #{man_attrib.ip_address}:#{man_attrib.listen_port}, >>
/tmp/wls_cluster"
end

Is this the right approach??
It’s always better to manage the whole resource if you can. If you
generated that file from a template earlier, it would be preferable to
merge the data you pass in to the template instead of appending to it like
this.

If you have no other option, then you should take care to ensure that this
won’t keep appending every time you run chef.

Thanks
Sachin


Daniel DeLeo

On Mon, Jun 8, 2015 at 7:04 PM, Fouts, Chris <Chris.Fouts@sensus.com
(mailto:Chris.Fouts@sensus.com)> wrote:

Try,

knife exec -E ‘nodes.find(:name => some_node) {|n|
n.set.ohs.wls_cluster = “ip_address : listen_port” ; n.save }’

Chris

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Monday, June 08, 2015 6:38 AM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Cc: sachin kumar
Subject: [chef] how to append an variable using chef

Hi All,

I need to set an attribute variable through chef recipe.

I an using a role file where I have defined weblogic cluster
information like

“wls_cluster”: {
“oci_cluster1”: {
“managed_servers”: {
“oci_man1”: {
“ip_address”: “10.10.10.31”,
“listen_port”: “7101”
},
“oci_man2”: {
“ip_address”: “10.10.10.32”,
“listen_port”: “7101”
}
}
},

my weblogic oci_cluster1 can have any number of managed servers, is
this example there are two

In my chef recipe i am using this code to fetch run time managed
servers information

node[:ohs][:wls_cluster].each do |cluster, cluster_attrib|
cluster_attrib.managed_servers.each do |managed_server, man_attrib|
Chef::Log.info (http://Log.info) “the IP address is
#{man_attrib.ip_address} and port is #{man_attrib.listen_port}”

node.set[:ohs][:wls_cluster] = "#{man_host}:#{man_port},"
Chef::Log.info (http://Log.info) “the value of wls_cluster are
#{node[:ohs][:wls_cluster]}”

end
end

I have an attribute variable default[:ohs][:wls_cluster] =’’ initially
set to null, I want to set this variable through chef recipe something like

[:ohs][:wls_cluster]=
“ip_address:listen_port,ip_address:listen_port,ip_address:listen_port…”

can anyone help how to append the variable values using chef.

Thanks & Regards,
Sachin Gupta