Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #42 from fnichol/COOK-1737

[COOK-1737] Fail a chef-solo run when passwords are not set.
  • Loading branch information...
commit 1de6b30d9fb368fad847ba2a6d8d4dfa125fb620 2 parents 7d72d69 + e53d1b7
Joshua Timberman jtimberman authored
Showing with 37 additions and 19 deletions.
  1. +18 −15 README.md
  2. +19 −4 recipes/server.rb
33 README.md
View
@@ -170,21 +170,6 @@ The recipe will perform a `node.save` unless it is run under
`chef-solo` after the password attributes are used to ensure that in
the event of a failed run, the saved attributes would be used.
-**Chef Solo Note**: These node attributes are stored on the Chef
- server when using `chef-client`. Because `chef-solo` does not
- connect to a server or save the node object at all, to have the same
- passwords persist across `chef-solo` runs, you must specify them in
- the `json_attribs` file used. For example:
-
- {
- "mysql": {
- "server_root_password": "iloverandompasswordsbutthiswilldo",
- "server_repl_password": "iloverandompasswordsbutthiswilldo",
- "server_debian_password": "iloverandompasswordsbutthiswilldo"
- },
- "run_list":["recipe[mysql::server]"]
- }
-
On EC2 nodes, use the `server_ec2` recipe and the mysql data dir will
be set up in the ephmeral storage.
@@ -199,6 +184,24 @@ For more infromation on the compile vs execution phase of a Chef run:
* http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run
+Chef Solo Note
+==============
+
+These node attributes are stored on the Chef
+server when using `chef-client`. Because `chef-solo` does not
+connect to a server or save the node object at all, to have the same
+passwords persist across `chef-solo` runs, you must specify them in
+the `json_attribs` file used. For example:
+
+ {
+ "mysql": {
+ "server_root_password": "iloverandompasswordsbutthiswilldo",
+ "server_repl_password": "iloverandompasswordsbutthiswilldo",
+ "server_debian_password": "iloverandompasswordsbutthiswilldo"
+ },
+ "run_list":["recipe[mysql::server]"]
+ }
+
License and Author
==================
23 recipes/server.rb
View
@@ -21,10 +21,25 @@
include_recipe "mysql::client"
-# generate all passwords
-node.set_unless['mysql']['server_debian_password'] = secure_password
-node.set_unless['mysql']['server_root_password'] = secure_password
-node.set_unless['mysql']['server_repl_password'] = secure_password
+if Chef::Config[:solo]
+ missing_attrs = %w{
+ server_debian_password server_root_password server_repl_password
+ }.select do |attr|
+ node["mysql"][attr].nil?
+ end.map { |attr| "node['mysql']['#{attr}']" }
+
+ if !missing_attrs.empty?
+ Chef::Application.fatal!([
+ "You must set #{missing_attrs.join(', ')} in chef-solo mode.",
+ "For more information, see https://github.com/opscode-cookbooks/mysql#chef-solo-note"
+ ].join(' '))
+ end
+else
+ # generate all passwords
+ node.set_unless['mysql']['server_debian_password'] = secure_password
+ node.set_unless['mysql']['server_root_password'] = secure_password
+ node.set_unless['mysql']['server_repl_password'] = secure_password
+end
if platform?(%w{debian ubuntu})
Please sign in to comment.
Something went wrong with that request. Please try again.