How can I capture the values ​​on the command line and add to the recipe?

I'm new to Chef and Ruby

I need to pass two variables to the chef on the command line and use these variables in the recipe.

How can I capture these values ​​and get them in the Chef?

I need something like this:

before_deploy command 
  execute param1 param2
deploy{ param1/param2}

Where param1and param2get their values ​​at run time from the command line.

+3
source share
3 answers

When you install the machine by running

chef-solo

or

chef-client

- , . - attributes. ( ) , : , , json .

, ,

  • json
  • chef-client chef-solo

: apache config.

json : my_attrs.json

{ 
  "apache": {
    "listen_port": "81",
    "listen_path": "/myapp"
  }
}

:

node[:apache][:listen_port]
node[:apache][:listen_path]

chef-client chef-solo -j.

chef-solo -j my_attrs.json

my_attrs.json - , URL-.

chef-solo -j http://remote.host/path/my_attrs.json
+7

example.rb

ruby example.rb argument1 argument2

ARGV.each do|a|
  puts "Argument: #{a}"
end

:

Argument: argument1
Argument: argument2
0

,

nodename = `cat /etc/chef/client.rb | grep "node_name" | sed -e 's/\<node_name\>//g' | sed '/^$/d;s/[[:blank:]]//g' | sed 's/\"//g'`

-

execute "echo nodename for node #{nodename}"
 command "echo #{nodename}"
 action :run
 only_if {nodename == "node1"}
end

node.name client.rb -.

0

All Articles