here path and nam1 are assigned variable. KIndly also tell me to changes to be made in sql file ???
$database = “aaaa”
powershell_script ‘script_name’ do
code <<-EOH
Invoke-sqlcmd -ServerInstance “#{nam1}” -InputFile “#{path}” -variable $database
EOH
end
@Ankur760 The Chef construct you are looking for here is a template
. The template
resource can be used to combine variables and a template file.
Templates are covered in the Learn the Basics module on our Learn Chef site: https://learn.chef.io/modules/learn-the-basics/windows/azure/make-your-recipe-more-manageable#/ and you can find more information here: https://docs.chef.io/resource_template.html#using-templates
thanks alot for your help…
Wish same in future
[quote=“Ankur760, post:3, topic:11462, full:true”]
thanks alot for your help…
thanks alot for your help…
Wish same in future
can you code one simple 2 line template for passing variables to sql file ?
simark
7
In your attribute file:
default['my_cookbook']['file']['variable'] = 'dynamic variable'
In your recipe:
template '~/target/location/of/generated/file.log' do
source 'template_file.log.erb'
variables(
var1: 'static variable',
var2: node['my_cookbook']['file']['variable']
)
end
in the template_file.log.erb
you can refere to the passed variables with the following syntax:
This is the var1 is variable content:<%= @var1 %>
This is the var2 is variable content:<%= @var2 %>
The template_file.log.erb
should be creted within your cookbook under ./templates/default
For further information check https://docs.chef.io/resource_template.html