I have chef recipe with this block :
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
I understand the template should by default create the file.
But it doesn't create the file and it gives the error No such file or directory
.
The template some_repo.rpm.repo.erb
itself looks like this:
[<%= @repo_name %>]
name=<%= @repo_name %>
baseurl=http://BLA.com//repos/<%= @os %>/<%= @distro %>
enabled=1
gpgcheck=0
sslverify=0
proxy=_none_
What am I doing wrong ?
EDIT :full error logs
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
EDIT2 : I know the issue is related to a block coming after the template i have this :
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
I wanted to copy the content of the file that the template created: "/etc/zypp/repos.d/some_repo" to /tmp/some.repos.d/some.repo
it seems like this block is creating the error with the template block which make the template not creating the new file, as a resulted the content IO.read block gets an error as the file was not created at the template stage.
this error only happed if i delete the file : /etc/zypp/repos.d/some_repo for testing to see if cookbook will re-create it. if this file exists no errors.
So, why "content IO.read" cancels "template" ?
This is the workaround :
Addings this line to the start of all blockes :
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
Then just duplicate the "template" block , for the other file :
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