用于PHP配置的厨师食谱获取错误密码而刀ssh'sudo chef-client'

时间:2015-09-29 14:30:21

标签: chef chef-recipe knife cookbook

我正在为PHP配置编写Chef cookbook,在使用刀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)

我已经加载了秘密文件和保存数据库密码的加密数据包项。仍然出现密码错误!

1 个答案:

答案 0 :(得分:0)

得到了解决方案!

我复制了以下行,其中包含“Webserver.rb”的数据库密码@ 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)

所以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

这很有用!