Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COOK-1737] Fail a chef-solo run when passwords are not set. #42

Merged
merged 1 commit into from
Oct 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
==================

Expand Down
23 changes: 19 additions & 4 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down