Hi All,
I have 2 recipes of which the first recipe creates a file and the second recipe reads the contents of this file and add in another file using a template.
When I gave a direct file read command in my second recipe, I got the error "ERROR: No such file or directory @ rb_sysopen when a run list is executed". So I have used a ruby_block with not_if guard and the compilation error is avoided. But now I am unable to read the value which is read from the file inside the ruby_block outside. hence my output file has no values for this field.
The command and recipe details are like this.
recipe 1 => creates a file
recipe 2 => reads the contents of the file created by recipe 1 and saves into another file which is created using a template
runlist is recipe1,recipe2
I tried using a global variable inside the ruby block, but that also not returning any value.
Following is the code snippet
#Read the ssh_public key to add as a field in json
$communicator = nil # Global Variable
def readKey()
ruby_block 'ssh_publicKeyText' do
block do
$communicator = File.read("/u01/app/paas/keys/ssh_public.pub")
end
only_if { File.exist?('/u01/app/paas/keys/ssh_public.pub') } # guard to avoid compile error when the file does not exists
end
return $communicator
end
vmPublicKeyText = readKey() # function call
template "/u01/app/paas/json/fcubs-dbcs-create.json" do
source "dbaas_schema.erb"
owner 'root'
group 'root'
mode '7777'
variables(
:serviceName => node['dbaas']['serviceName'],
:version => node['dbaas']['version'],
:level => node['dbaas']['level'],
:edition => node['dbaas']['edition'],
:subscriptionType => node['dbaas']['subscriptionType'],
:description => node['dbaas']['description'],
:shape => node['dbaas']['shape'],
:type => node['dbaas']['parameters_array']['type'],
:usableStorage => node['dbaas']['parameters_array']['usableStorage'],
:adminPassword => node['dbaas']['parameters_array']['adminPassword'],
:sid => node['dbaas']['parameters_array']['sid'],
:pdb => node['dbaas']['parameters_array']['pdb'],
:failoverDatabase => node['dbaas']['parameters_array']['failoverDatabase'],
:backupDestination => node['dbaas']['parameters_array']['backupDestination'],
:cloudStorageContainer => node['dbaas']['parameters_array']['cloudStorageContainer'],
:cloudStorageUser => node['dbaas']['parameters_array']['cloudStorageUser'],
:cloudStoragePwd => node['dbaas']['parameters_array']['cloudStoragePwd'],
:vmPublicKeyText => vmPublicKeyText # variable for keytext