I have struggle with getting data bags data into my recipe:
Here is the recipe:
sql_password = Chef::EncryptedDataBagItem.load('mysql', 'password')
service 'mysqld' do
action [:start, :enable]
only_if { node['lamp']['mysql']['install_sql'] }
end
bash 'mysql-install' do
user 'root'
cwd '/tmp'
code <<-EOH
expect -c "
set timeout 10
spawn mysql_secure_installation
expect \\"Enter current password for root (enter for none):\\"
send \\"\r\\"
expect \\"Change the root password?\\"
send \\"y\r\\"
expect \\"New password:\\"
send \\"#{sql_password['mysql_password']}\r\\"
expect \\"Re-enter new password:\\"
send \\"#{sql_password['mysql_password']}\r\\"
expect \\"Remove anonymous users?\\"
send \\"y\r\\"
expect \\"Disallow root login remotely?\\"
send \\"y\r\\"
expect \\"Remove test database and access to it?\\"
send \\"y\r\\"
expect \\"Reload privilege tables now?\\"
send \\"y\r\\"
expect eof"
EOH
only_if { node['lamp']['mysql']['install_sql'] }
end
ruby_block 'set install_sql' do
block do
node.set['lamp']['mysql']['install_sql'] = false
node.save
end
action :run
end
Here is the Data bag:
{ "id":"mysql", "root_password":"C1sc0123", "admin_password":"C1sc0123" }
This the error i'm getting:
Net::HTTPServerException ubunutunode4 ------------------------ ubunutunode4 404 "Object Not Found" ubunutunode4 ubunutunode4 Cookbook Trace: ubunutunode4 --------------- ubunutunode4 /var/chef/cache/cookbooks/lamp/recipes/mysql.rb:1:in `from_file' ubunutunode4 /var/chef/cache/cookbooks/lamp/recipes/default.rb:12:in `from_file' ubunutunode4 /var/chef/cache/cookbooks/lamp_app/recipes/default.rb:6:in `from_file' ubunutunode4 ubunutunode4 Relevant File Content: ubunutunode4 ---------------------- ubunutunode4 /var/chef/cache/cookbooks/lamp/recipes/mysql.rb: ubunutunode4 ubunutunode4 1>> sql_password = Chef::EncryptedDataBagItem.load('mysql', 'password') ubunutunode4 2: ubunutunode4 3: service 'mysqld' do ubunutunode4 4: action [:start,:enable] ubunutunode4 5: only_if { node['lamp']['mysql']['install_sql'] } ubunutunode4 6: end ubunutunode4 7: ubunutunode4 8: bash 'mysql-install' do ubunutunode4 9: user 'root' ubunutunode4 10: cwd '/tmp'