厨师模板给出没有这样的文件或目录@ rb_sysopen Errno::ENOENT
chef template gives No such file or directory @ rb_sysopen Errno::ENOENT
我有这个方块的厨师食谱:
if ( platform === 'suse' )
repo_name="some_repo"
template '/etc/zypp/repos.d/some_repo' do
source 'some_repo.rpm.repo.erb'
variables( :os => "#{os}", :distro => "#{distro}", :repo_name => "#{repo_name}" )
owner "root"
group "root"
mode '644'
end
end
我知道模板应该默认创建文件。
但它不会创建文件并给出错误 No such file or directory
.
模板 some_repo.rpm.repo.erb
本身如下所示:
[<%= @repo_name %>]
name=<%= @repo_name %>
baseurl=http://BLA.com//repos/<%= @os %>/<%= @distro %>
enabled=1
gpgcheck=0
sslverify=0
proxy=_none_
我做错了什么?
编辑:完整错误日志
Recipe Compile Error in /tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb
================================================================================
Errno::ENOENT
-------------
No such file or directory @ rb_sysopen - /etc/zypp/repos.d/some_repo
Cookbook Trace:
---------------
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb:106:in `read'
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb:106:in `block in from_file'
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb:104:in `from_file'
Relevant File Content:
----------------------
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/zabbix_agent/recipes/default.rb:
99: owner 'root'
100: group 'root'
101: mode '0755'
102: action :create
103: end
104: file '/tmp/some.repos.d/some.repo' do
105: mode '0644'
106>> content IO.read(node['somepackage'][node['platform']]['repo_source'])
107: action :create
108: end
109: end
110:
111: ######### Install package ###########
112: #package 'somepackage' do
113: # action :install
114: #end
115: node['somepackage'][node['platform']]['packages'].each do |pkg|
System Info:
------------
chef_version=14.2.0
platform=redhat
platform_version=7.5
ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
program_name=/bin/chef-solo
executable=/opt/chef/bin/chef-solo
Running handlers:
[2019-02-10T11:32:27+02:00] ERROR: Running exception handlers
[2019-02-10T11:32:27+02:00] ERROR: Running exception handlers
Running handlers complete
[2019-02-10T11:32:27+02:00] ERROR: Exception handlers complete
[2019-02-10T11:32:27+02:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 11 seconds
[2019-02-10T11:32:27+02:00] FATAL: Stacktrace dumped to /tmp/ldt_chef_run/local-mode-cache/cache/chef-stacktrace.out
[2019-02-10T11:32:27+02:00] FATAL: Stacktrace dumped to /tmp/ldt_chef_run/local-mode-cache/cache/chef-stacktrace.out
[2019-02-10T11:32:27+02:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-02-10T11:32:27+02:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-02-10T11:32:27+02:00] FATAL: Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/zypp/repos.d/some_repo
[2019-02-10T11:32:27+02:00] FATAL: Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/zypp/repos.d/some_repo
编辑2:
我知道这个问题与 之后的一个区块有关
模板我有这个:
if %w(redhat suse sles).include?(node['platform'])
directory '/tmp/some.repos.d' do
owner 'root'
group 'root'
mode '0755'
action :create
end
file '/tmp/some.repos.d/some.repo' do
mode '0644'
content IO.read(node['somepakage'][node['platform']]['repo_source'])
action :create
end
end
我想复制模板创建的文件的内容:
“/etc/zypp/repos.d/some_repo”
到 /tmp/some.repos.d/some.repo
似乎此块正在使用模板块创建错误
这使得模板不创建新文件,结果是
content IO.read 块出现错误,因为文件不是在模板阶段创建的。
这个错误只有在我删除文件时才会发生:
/etc/zypp/repos.d/some_repo
用于测试食谱是否会重新创建它。
如果这个文件存在没有错误。
那么,为什么 "content IO.read" 取消 "template"?
这是解决方法:
将此行添加到所有块的开头:
if %w(redhat suse sles ubuntu debian).include?(node['platform'])
directory '/tmp/some.repos.d' do
owner 'root'
group 'root'
mode '0755'
action :create
end
end
然后复制 "template" 块,用于另一个文件:
if ( platform === 'suse' )
repo_name="some_repo"
template '/etc/zypp/repos.d/some.repo' do
source 'some.rpm.repo.erb'
variables( :os => "#{os}", :distro => "#{distro}", :repo_name => "#{repo_name}" )
owner "root"
group "root"
mode '644'
end
template '/tmp/some.repos.d/some.repo' do
source 'some.rpm.repo.erb'
variables( :os => "#{os}", :distro => "#{distro}", :repo_name => "#{repo_name}" )
owner "root"
group "root"
mode '644'
end
end
我有这个方块的厨师食谱:
if ( platform === 'suse' )
repo_name="some_repo"
template '/etc/zypp/repos.d/some_repo' do
source 'some_repo.rpm.repo.erb'
variables( :os => "#{os}", :distro => "#{distro}", :repo_name => "#{repo_name}" )
owner "root"
group "root"
mode '644'
end
end
我知道模板应该默认创建文件。
但它不会创建文件并给出错误 No such file or directory
.
模板 some_repo.rpm.repo.erb
本身如下所示:
[<%= @repo_name %>]
name=<%= @repo_name %>
baseurl=http://BLA.com//repos/<%= @os %>/<%= @distro %>
enabled=1
gpgcheck=0
sslverify=0
proxy=_none_
我做错了什么?
编辑:完整错误日志
Recipe Compile Error in /tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb
================================================================================
Errno::ENOENT
-------------
No such file or directory @ rb_sysopen - /etc/zypp/repos.d/some_repo
Cookbook Trace:
---------------
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb:106:in `read'
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb:106:in `block in from_file'
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/recipes/default.rb:104:in `from_file'
Relevant File Content:
----------------------
/tmp/ldt_chef_run/local-mode-cache/cache/cookbooks/zabbix_agent/recipes/default.rb:
99: owner 'root'
100: group 'root'
101: mode '0755'
102: action :create
103: end
104: file '/tmp/some.repos.d/some.repo' do
105: mode '0644'
106>> content IO.read(node['somepackage'][node['platform']]['repo_source'])
107: action :create
108: end
109: end
110:
111: ######### Install package ###########
112: #package 'somepackage' do
113: # action :install
114: #end
115: node['somepackage'][node['platform']]['packages'].each do |pkg|
System Info:
------------
chef_version=14.2.0
platform=redhat
platform_version=7.5
ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
program_name=/bin/chef-solo
executable=/opt/chef/bin/chef-solo
Running handlers:
[2019-02-10T11:32:27+02:00] ERROR: Running exception handlers
[2019-02-10T11:32:27+02:00] ERROR: Running exception handlers
Running handlers complete
[2019-02-10T11:32:27+02:00] ERROR: Exception handlers complete
[2019-02-10T11:32:27+02:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 11 seconds
[2019-02-10T11:32:27+02:00] FATAL: Stacktrace dumped to /tmp/ldt_chef_run/local-mode-cache/cache/chef-stacktrace.out
[2019-02-10T11:32:27+02:00] FATAL: Stacktrace dumped to /tmp/ldt_chef_run/local-mode-cache/cache/chef-stacktrace.out
[2019-02-10T11:32:27+02:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-02-10T11:32:27+02:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-02-10T11:32:27+02:00] FATAL: Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/zypp/repos.d/some_repo
[2019-02-10T11:32:27+02:00] FATAL: Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/zypp/repos.d/some_repo
编辑2: 我知道这个问题与 之后的一个区块有关 模板我有这个:
if %w(redhat suse sles).include?(node['platform'])
directory '/tmp/some.repos.d' do
owner 'root'
group 'root'
mode '0755'
action :create
end
file '/tmp/some.repos.d/some.repo' do
mode '0644'
content IO.read(node['somepakage'][node['platform']]['repo_source'])
action :create
end
end
我想复制模板创建的文件的内容: “/etc/zypp/repos.d/some_repo” 到 /tmp/some.repos.d/some.repo
似乎此块正在使用模板块创建错误 这使得模板不创建新文件,结果是 content IO.read 块出现错误,因为文件不是在模板阶段创建的。
这个错误只有在我删除文件时才会发生: /etc/zypp/repos.d/some_repo 用于测试食谱是否会重新创建它。 如果这个文件存在没有错误。
那么,为什么 "content IO.read" 取消 "template"?
这是解决方法:
将此行添加到所有块的开头:
if %w(redhat suse sles ubuntu debian).include?(node['platform'])
directory '/tmp/some.repos.d' do
owner 'root'
group 'root'
mode '0755'
action :create
end
end
然后复制 "template" 块,用于另一个文件:
if ( platform === 'suse' )
repo_name="some_repo"
template '/etc/zypp/repos.d/some.repo' do
source 'some.rpm.repo.erb'
variables( :os => "#{os}", :distro => "#{distro}", :repo_name => "#{repo_name}" )
owner "root"
group "root"
mode '644'
end
template '/tmp/some.repos.d/some.repo' do
source 'some.rpm.repo.erb'
variables( :os => "#{os}", :distro => "#{distro}", :repo_name => "#{repo_name}" )
owner "root"
group "root"
mode '644'
end
end