Chef 无法找到存在于食谱中的文件 - Chef::Exceptions::FileNotFound

Chef 无法找到存在于食谱中的文件 - Chef::Exceptions::FileNotFound

我在 Chef 中部署食谱时遇到了麻烦。但是,它找不到它所寻找的目录中存在的文件。

我的配方安装并启动了 Apache,然后应该用我生成的简单模板替换默认的 index.html,但它在食谱中找不到我修改过的 index.html.erb,所以不要替换它。

这是我的环境:

打印版本可能会有用:

[root@centos-bpo1 cookbooks]# chef --version
Chef Development Kit Version: 2.3.4
chef-client version: 13.4.19
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.17.0
inspec version: 1.36.1

打印我的食谱“httpd_deploy”的内容:

[root@centos-bpo1 cookbooks]# cd httpd_deploy/
[root@centos-bpo1 httpd_deploy]# tree
.
├── Berksfile
├── chefignore
├── httpd_deploy
│   └── templates
│       └── index.html.erb
├── LICENSE
├── metadata.rb
├── README.md
├── recipes
│   └── default.rb
├── spec
│   ├── spec_helper.rb
│   └── unit
│       └── recipes
│           └── default_spec.rb
└── test
    └── smoke
        └── default
            └── default_test.rb

打印配方“httpd_deploy”的内容:

[root@centos-bpo1 httpd_deploy]# cat recipes/default.rb
#
# Cookbook:: httpd_deploy
# Recipe:: default
#
# Copyright:: 2017, The Authors, All Rights Reserved.
package 'httpd'
service 'httpd' do
action [:enable, :start]
end
template '/var/www/html/index.html' do
source 'index.html.erb'
end

打印源文件“index.html.erb”的内容:

[root@centos-bpo1 httpd_deploy]# cat httpd_deploy/templates/index.html.erb
Welcome to Chef Apache Deployment 

我正在使用以下命令启动该食谱作为本地测试:

[root@centos-bpo1 httpd_deploy]# cd ..
[root@centos-bpo1 cookbooks]# chef-client --local-mode --runlist 'recipe[httpd_deploy]'

结果如下(截断):

[2017-10-02T10:58:22+02:00] ERROR: template[/var/www/html/index.html] (httpd_deploy::default line 10) had an error: Chef::Exceptions::FileNotFound: Cookbook 'httpd_deploy' (0.1.0) does not contain a file at any of these locations:
  templates/centos-7.4.1708/index.html.erb
  templates/centos/index.html.erb
  templates/default/index.html.erb
  templates/index.html.erb

答案1

正如错误消息所示,您需要将模板templates/index.html.erb放在httpd_deploy/templates/index.html.erb

相关内容