Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jblaine
Created October 27, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblaine/a297b669eecdf745379071b1a0c07b0b to your computer and use it in GitHub Desktop.
Save jblaine/a297b669eecdf745379071b1a0c07b0b to your computer and use it in GitHub Desktop.
FileUtils.mv being EXECUTED at compile time from a library method?
# PART 1, THE EXCEPTION:
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/r701-apache/recipes/mcran-server.rb
================================================================================
Errno::ENOENT
-------------
No such file or directory @ rb_file_s_rename - (/tmp/r701-apache-tmp-certs.pem, /etc/httpd/conf/../supporting_certs/certs.pem)
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/r701-apache/libraries/helpers.rb:69:in `cert_bundle_from_databag_items'
/var/chef/cache/cookbooks/r701-apache/libraries/helpers.rb:33:in `install_supporting_certs'
/var/chef/cache/cookbooks/r701-apache/recipes/mcran-server.rb:15:in `from_file'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/r701-apache/libraries/helpers.rb:
68:
69>> FileUtils.mv("#{tmpdir}/#{tmpbundle}", node['r701-apache']['certificate_chain_file'])
70: return false
71: end
72:
# PART 2: THE RECIPE
install_supporting_certs
# END
# PART 3: THE LIBRARY METHODS (libraries/helpers.rb)
def supporting_certs_dir
return "#{node['r701-apache']['conf-dir']}/../supporting_certs"
end
def install_supporting_certs(bundle_filename='certs.pem', cert_ids=['ca-1', 'ca-3'])
directory supporting_certs_dir do
owner 'root'
group 'root'
mode '0755'
end
cert_bundle_from_databag_items(cert_ids)
end
def cert_bundle_from_databag_items(cert_ids)
tmpbundle = '/tmp/r701-apache-tmp-certs.pem'
if node['platform'] == 'windows'
tmpbundle = '/windows/temp/r701-apache-tmp-certs.pem'
end
::File.unlink(tmpbundle) if ::File.exist?(tmpbundle)
cert_ids.each do |id|
certdata = data_bag_item('supporting_certs', id)['certificate']
::File.open(tmpbundle, 'a') { |file| file.write(certdata) }
end
FileUtils.mv(tmpbundle, node['r701-apache']['certificate_chain_file'])
end
# END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment