Unusual behavior of attributes as node object is not getting reset during client run


#1

Hello,

I am working on a recipe of DB2 installation where the User and group
information changes with every DB2 version.

So, I put user and group info in data bag and trying to override the
information in attribute file with the data_bag info.

This is what i did :-
<<< ----
In data_bag :-
{“id”:“db2”,“V9.1”:{“uid”:“9001”,“uname”:“db91inst”,“gid”:“9100”,“gname”:“db9grp”},“V9.5”:{“uid”:“9005”,“uname”:“db95inst”,“gid”:“9100”,“gname”:“db9grp”}}

In attribute file:-
default[:db2][:version] = "V9.5"
default[:db2][:uid] = "uid"
default[:db2][:user] = "db2user"
default[:db2][:gid] = "gid"
default[:db2][:group] = "db2grp"
default[:net][:user] = {node[:db2][:uid] => [ node[:db2][:user], “db2
user”, node[:db2][:db2home]] }
default[:net][:group] = { node[:db2][:gid] => node[:db2][:group] }

In recipe file :-
db2client = node[:db2]
version = db2client[:version]
node.set[:db2][:uid] = DB2InstallInfo.getInstallUserId(version)
db2client[:user][“db2user”] = DB2InstallInfo.getInstallUserName(version)
node.set[:db2][:gid] = DB2InstallInfo.getInstallGroupId(version)
db2client[:group][“db2grp”] = DB2InstallInfo.getInstallGroupName(version)

ruby_block “test” do
block do
puts node[:net][:user], node[:net][:group]
end
end

In Library File :-
require ‘chef’
$installerInfo = Chef::DataBagItem.load(‘dbclient’, ‘db2’)
class DB2InstallInfo
def self.getInstallUserId(version)
userId = $installerInfo[version]
return userId[“uid”]
end
def self.getInstallUserName(version)
userId = $installerInfo[version]
return userId[“uname”]
end
def self.getInstallGroupId(version)
userId = $installerInfo[version]
return userId[“gid”]
end
def self.getInstallGroupName(version)
userId = $installerInfo[version]
return userId[“gname”]
end
end

------ >>>>

And On Chef Client run, I am getting this on two consecutive run after
changing version no in attribute file
:-
<<<< -----
[root@mrigesh~]# chef-client -o recipe[db2client::test] -l error
Starting Chef Client, version 11.6.0
resolving cookbooks for run list: [“db2client::test”]
Synchronizing Cookbooks:

  • db2client
    Compiling Cookbooks…
    Converging 1 resources
    Recipe: db2client::test
  • ruby_block[test] action run{“9001”=>[“db95inst”, “db2 user”,
    "/opt/ibm/db2"]}
    {“9100”=>“db9grp”}

    • execute the ruby block test

Chef Client finished, 1 resources updated

[root@mrigesh~]# chef-client -o recipe[db2client::test] -l error
Starting Chef Client, version 11.6.0
resolving cookbooks for run list: [“db2client::test”]
Synchronizing Cookbooks:

  • db2client
    Compiling Cookbooks…
    Converging 1 resources
    Recipe: db2client::test
  • ruby_block[test] action run{“9005”=>[“db95inst”, “db2 user”,
    "/opt/ibm/db2"]}
    {“9100”=>“db9grp”}

    • execute the ruby block test

Chef Client finished, 1 resources updated
[root@mrigesh~]

--------- >>>>

Its very confusing, please guide.

Warm Regards,

Mrigesh Priyadarshi


#2

On Wednesday, October 23, 2013 at 6:30 AM, Mrigesh Priyadarshi wrote:

Hello,

I am working on a recipe of DB2 installation where the User and group information changes with every DB2 version.

So, I put user and group info in data bag and trying to override the information in attribute file with the data_bag info.

This is what i did :-
<<< ----
In data_bag :-
{“id”:“db2”,“V9.1”:{“uid”:“9001”,“uname”:“db91inst”,“gid”:“9100”,“gname”:“db9grp”},“V9.5”:{“uid”:“9005”,“uname”:“db95inst”,“gid”:“9100”,“gname”:“db9grp”}}

In attribute file:-
default[:db2][:version] = "V9.5"
default[:db2][:uid] = "uid"
default[:db2][:user] = "db2user"
default[:db2][:gid] = "gid"
default[:db2][:group] = "db2grp"
default[:net][:user] = {node[:db2][:uid] => [ node[:db2][:user], “db2 user”, node[:db2][:db2home]] }
On the first pass, you set node[:net][:user] to {node[:db2][:uid] => [ node[:db2][:user], “db2 user”, node[:db2][:db2home]] }

default[:net][:group] = { node[:db2][:gid] => node[:db2][:group] }

In recipe file :-
db2client = node[:db2]
version = db2client[:version]
node.set[:db2][:uid] = DB2InstallInfo.getInstallUserId(version)
Here, you change node[:db2][:uid] to a new value. This does not update node[:net][:user], but it does set node[:db2][:uid] to a persistent attribute (belongs to the node itself and is independent of any roles/recipes applied to the node).

default[:net][:user] = {node[:db2][:uid] => [ node[:db2][:user], “db2 user”, node[:db2][:db2home]] }
On the second run, node[:db2][:uid] is going to be the value that you set in the recipe, because it “pre-exists” on the node and is higher precedence than the default value you set in the attributes file.

You can probably make everything a lot simpler if you set all your attributes in one place, if possible.


Daniel DeLeo


#3

Thanks Daniel. That(Putting all attributes on one location) was also on my
mind but I wanted to put all attributes in attributes file only and calling
library function in attribute file was failing.

Anyhow, I put the below two lines in recipe only and it worked like a charm.
<<< ====
node.default[:net][:user] = {node[:db2][:uid] => [ node[:db2][:user], “db2
user”, node[:db2][:db2home]] }
node.default[:net][:group] = { node[:db2][:gid] => node[:db2][:group] }
======= >>>

Thanks again for the help.

Warm Regards,

Mrigesh Priyadarshi

On Thu, Oct 24, 2013 at 4:16 AM, Daniel DeLeo dan@kallistec.com wrote:

On Wednesday, October 23, 2013 at 6:30 AM, Mrigesh Priyadarshi wrote:

Hello,

I am working on a recipe of DB2 installation where the User and group
information changes with every DB2 version.

So, I put user and group info in data bag and trying to override the
information in attribute file with the data_bag info.

This is what i did :-
<<< ----
In data_bag :-

{“id”:“db2”,“V9.1”:{“uid”:“9001”,“uname”:“db91inst”,“gid”:“9100”,“gname”:“db9grp”},“V9.5”:{“uid”:“9005”,“uname”:“db95inst”,“gid”:“9100”,“gname”:“db9grp”}}

In attribute file:-
default[:db2][:version] = "V9.5"
default[:db2][:uid] = "uid"
default[:db2][:user] = "db2user"
default[:db2][:gid] = "gid"
default[:db2][:group] = "db2grp"
default[:net][:user] = {node[:db2][:uid] => [ node[:db2][:user], “db2
user”, node[:db2][:db2home]] }

On the first pass, you set node[:net][:user] to {node[:db2][:uid] => [
node[:db2][:user], “db2 user”, node[:db2][:db2home]] }

default[:net][:group] = { node[:db2][:gid] => node[:db2][:group] }

In recipe file :-
db2client = node[:db2]
version = db2client[:version]
node.set[:db2][:uid] = DB2InstallInfo.getInstallUserId(version)

Here, you change node[:db2][:uid] to a new value. This does not update
node[:net][:user], but it does set node[:db2][:uid] to a persistent
attribute (belongs to the node itself and is independent of any
roles/recipes applied to the node).

default[:net][:user] = {node[:db2][:uid] => [ node[:db2][:user], “db2
user”, node[:db2][:db2home]] }

On the second run, node[:db2][:uid] is going to be the value that you set
in the recipe, because it “pre-exists” on the node and is higher precedence
than the default value you set in the attributes file.

You can probably make everything a lot simpler if you set all your
attributes in one place, if possible.


Daniel DeLeo