PHP 配置的 chef cookbook 在 knife ssh 'sudo chef-client' 时获取错误密码
chef cookbook for PHP configuration getting error password while knife ssh 'sudo chef-client'
我正在为 PHP 配置编写 Chef cookbook,knife ssh 时出现密码错误 'sudo chef-client'
Webserver.rb :
#
# Cookbook Name:: awesome_customers
# Recipe:: webserver
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
# Install Apache and start the service.
httpd_service 'customers' do
mpm 'prefork'
action [:create, :start]
end
# Write the home page.
template "#{node['awesome_customers']['document_root']}/index.php" do
# content '<html>This is a placeholder</html>'
source 'index.php.erb'
mode '0644'
owner node['awesome_customers']['user']
group node['awesome_customers']['group']
variables({
:database_password => user_password_data_bag_item['password']
})
end
# Install the mod_php5 Apache module.
httpd_module 'php5' do
instance 'customers'
end
# Install php5-mysql.
package 'php5-mysql' do
action :install
notifies :restart, 'httpd_service[customers]'
end
# Load the secrets file and the encrypted data bag item that holds the database password.
password_secret = Chef::EncryptedDataBagItem.load_secret(node['awesome_customers']['passwords']['secret_path'])
user_password_data_bag_item = Chef::EncryptedDataBagItem.load('passwords', 'db_admin_password', password_secret)
错误输出:
54.153.93.47 Recipe Compile Error in /var/chef/cache/cookbooks/awesome_customers/recipes/default.rb
54.153.93.47 NoMethodError
54.153.93.47 undefined method `user_password_data_bag_item' for Chef::Resource::Template
54.153.93.47 32>> :database_password => user_password_data_bag_item['password']
54.153.93.47 [2015-09-29T10:41:56+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
我加载了secrets文件和保存数据库密码的加密数据包项。仍然收到密码错误!
找到答案了!
我在 "Webserver.rb" 的末尾复制了以下包含数据库密码的行。由于顺序在配方中很重要,因此它应该在主页的模板资源之前。
# Load the secrets file and the encrypted data bag item that holds the database password.
password_secret = Chef::EncryptedDataBagItem.load_secret(node['awesome_customers']['passwords']['secret_path'])
user_password_data_bag_item = Chef::EncryptedDataBagItem.load('passwords', 'db_admin_password', password_secret)
所以 Webserver.rb 看起来像 :
#
# Cookbook Name:: awesome_customers
# Recipe:: webserver
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
# Install Apache and start the service.
httpd_service 'customers' do
mpm 'prefork'
action [:create, :start]
end
# Load the secrets file and the encrypted data bag item that holds the database password.
password_secret = Chef::EncryptedDataBagItem.load_secret(node['awesome_customers']['passwords']['secret_path'])
user_password_data_bag_item = Chef::EncryptedDataBagItem.load('passwords', 'db_admin_password', password_secret)
# Write the home page.
template "#{node['awesome_customers']['document_root']}/index.php" do
# content '<html>This is a placeholder</html>'
source 'index.php.erb'
mode '0644'
owner node['awesome_customers']['user']
group node['awesome_customers']['group']
variables({
:database_password => user_password_data_bag_item['password']
})
end
# Install the mod_php5 Apache module.
httpd_module 'php5' do
instance 'customers'
end
# Install php5-mysql.
package 'php5-mysql' do
action :install
notifies :restart, 'httpd_service[customers]'
end
这有效!
我正在为 PHP 配置编写 Chef cookbook,knife ssh 时出现密码错误 'sudo chef-client'
Webserver.rb :
#
# Cookbook Name:: awesome_customers
# Recipe:: webserver
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
# Install Apache and start the service.
httpd_service 'customers' do
mpm 'prefork'
action [:create, :start]
end
# Write the home page.
template "#{node['awesome_customers']['document_root']}/index.php" do
# content '<html>This is a placeholder</html>'
source 'index.php.erb'
mode '0644'
owner node['awesome_customers']['user']
group node['awesome_customers']['group']
variables({
:database_password => user_password_data_bag_item['password']
})
end
# Install the mod_php5 Apache module.
httpd_module 'php5' do
instance 'customers'
end
# Install php5-mysql.
package 'php5-mysql' do
action :install
notifies :restart, 'httpd_service[customers]'
end
# Load the secrets file and the encrypted data bag item that holds the database password.
password_secret = Chef::EncryptedDataBagItem.load_secret(node['awesome_customers']['passwords']['secret_path'])
user_password_data_bag_item = Chef::EncryptedDataBagItem.load('passwords', 'db_admin_password', password_secret)
错误输出:
54.153.93.47 Recipe Compile Error in /var/chef/cache/cookbooks/awesome_customers/recipes/default.rb
54.153.93.47 NoMethodError
54.153.93.47 undefined method `user_password_data_bag_item' for Chef::Resource::Template
54.153.93.47 32>> :database_password => user_password_data_bag_item['password']
54.153.93.47 [2015-09-29T10:41:56+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
我加载了secrets文件和保存数据库密码的加密数据包项。仍然收到密码错误!
找到答案了!
我在 "Webserver.rb" 的末尾复制了以下包含数据库密码的行。由于顺序在配方中很重要,因此它应该在主页的模板资源之前。
# Load the secrets file and the encrypted data bag item that holds the database password.
password_secret = Chef::EncryptedDataBagItem.load_secret(node['awesome_customers']['passwords']['secret_path'])
user_password_data_bag_item = Chef::EncryptedDataBagItem.load('passwords', 'db_admin_password', password_secret)
所以 Webserver.rb 看起来像 :
#
# Cookbook Name:: awesome_customers
# Recipe:: webserver
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
# Install Apache and start the service.
httpd_service 'customers' do
mpm 'prefork'
action [:create, :start]
end
# Load the secrets file and the encrypted data bag item that holds the database password.
password_secret = Chef::EncryptedDataBagItem.load_secret(node['awesome_customers']['passwords']['secret_path'])
user_password_data_bag_item = Chef::EncryptedDataBagItem.load('passwords', 'db_admin_password', password_secret)
# Write the home page.
template "#{node['awesome_customers']['document_root']}/index.php" do
# content '<html>This is a placeholder</html>'
source 'index.php.erb'
mode '0644'
owner node['awesome_customers']['user']
group node['awesome_customers']['group']
variables({
:database_password => user_password_data_bag_item['password']
})
end
# Install the mod_php5 Apache module.
httpd_module 'php5' do
instance 'customers'
end
# Install php5-mysql.
package 'php5-mysql' do
action :install
notifies :restart, 'httpd_service[customers]'
end
这有效!