Hi All,
I have bash script to creating stores in openstack. My scenarios is like below:-
Parameter is passed along cookbook when execute them , this is a store name like store 1 , store 2
For example :- If i want to create a store 5 then i will call cookbook named "store-automation-cookbook " along with store name store 5, this store name in-turn will be passing to BASH script
then BASH script will take care rest of the automation
Any one can reply plz ? Its urgent
I may not be understanding your questions fully but could you not do something like
bash ârun main.shâ do
cwd ::File.dirname(â/usr/local/binâ)
code <<-EOH
./main.sh --store_id #{node[âstoreidâ]}
EOH
end
Hi,
Thanks for the reply. I will explain you in details.
I have BASH shell script, and I called it in recipe like
cookbook/default.rb
execute âExecute my scriptâ do
user 'rootâ
cwd '/rootâ
command './hello_world.shâ
end
When I run the Cookbook like
chef-client -z -o app [Store_name]
i.e Store_name is variable in bash script will take the value from Store Name, will apply to BASH script inside recipe.
How about you try and pass json attributes for example
chef-client -z -j node.json
This way you can pass in attribute information into the cookbook.
I still think you would need to pass the variable for the sh script like command './hello_world.sh
--store_name â#{node[âstore_nameâ]}â
1 Like
Chef doesnât really have a good way to take command line input like that. Using -j
as mentioned is possible but you might end up setting more things that you meant to. Using environment variables is another option but only works from the command line for the most part. A hybrid of the two might be best for you, consume the env var if set, otherwise use a node attribute.
Hi,
How can we achieve this with json file ?
Below are my code
cookbook/script/recipes/default.rb
bash ârun main.shâ do
cwd ::File.dirname(â/root/â)
code <<-EOH
./root/hello_world.sh --admin_password #{node[âadmin_passwordâ]}
EOH
end
cookbook/script/attributes/default.rb
default[âscriptâ][âadmin_passwordâ] = "John"
admin_password = node[âscriptâ][âadmin_passwordâ]
default[:script][:admin_password]= âxyâ
my_attrs.json
{
âscriptâ: {
âadmin_passwordâ:âchetanâ
}
}
I am calling the script cookbook as below
chef-client -z -o script -j my_attrs.json
But i am getting syntax error and not able to change/pass value from json file
Can you plz help me ?