Parse files from "nodes/*.json" to help you integrate your Chef-Solo nodes with Capistrano, Knife-Solo, SSH, etc.
The .json file can optionally define any of the following attributes:
- "ipaddress" - If not defined, file name used: node/[FILE_NAME].json
- "user" || "login"
- "port"
{
"ipaddress": "localhost",
"port": 2222,
"user": "vagrant",
/* Your other Chef-related attributes. */
/* Ignored by Chef_Solo_Nodes. */
"roles": ["dev"],
"run_list": [ "recipe[...]", "recipe[....]"]
}
Most of the action is in less than 100 lines of code.
gem install Chef_Solo_Nodes
Provides two functions: Chef_Solo_Nodes(), Chef_Solo_IPs(). You can pass them an optional role name to filter the nodes.
require "Chef_Solo_Nodes"
Chef_Solo_Nodes() # ===> [ Hash, Hash ]
Chef_Solo_Nodes('role_name') # ===> [ Hash, Hash ]
Chef_Solo_IPs('db') # ===> [ "hostname", "user@hostname:port" ]
If the argument is an Array, it will treat each element as a file path to a JSON file:
paths = [ "node/FILE_1.json", "node/FILE_2.json" ]
Chef_Solo_Nodes paths
Chef_Solo_IPs paths
require "Chef_Solo_Nodes"
role :app, *Chef_Solo_IPs('app')
role :db, *Chef_Solo_IPs('db')
Equivalent to:
role :app, "user@host:port", "192.0.0.42"
role :db, "super.secret.base"
Provides 2 executables: IP and SSH
They are meant to generate arguments for other programs:
$ ping -c 3 $( IP --no-user file_name )
ping -c 3 my.ip.address
$ ssh $( SSH file_name )
ssh -p 2222 [email protected]
$ knife prepare $( SSH file_name )
knife prepare -p 4567 [email protected]
Tip: the last example above uses knife-solo.
Errors: If the file is not found, they print xx.xx.xx.xx to standard output and exit 1. Unexpected, unplanned errors are printed to standard error.
$ IP file_name # parses node/file_name.json
Depending on whether the attributes exist, the results could take any form of the following:
127.0.0.1
127.0.0.1:2222
[email protected]:2222
Remove user@ with: IP --no-user file_name
$ SSH file_name # parses node/file_name.json
Depending on whether the attributes exist, the results could take any form of the following:
127.0.0.1
[email protected]
-p 2222 [email protected]
Remove user@ with: SSH --no-user file_name
git clone [email protected]:da99/Chef_Solo_Nodes.git
cd Chef_Solo_Nodes
bundle update
bundle exec bacon spec/main.rb
If you know of existing software that makes the above redundant, please tell me. The last thing I want to do is maintain code.