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