Class: Formatron::Chef::Berkshelf
- Inherits:
-
Object
- Object
- Formatron::Chef::Berkshelf
- Defined in:
- lib/formatron/chef/berkshelf.rb
Overview
Wrapper for the berkshelf cli
Constant Summary collapse
- CONFIG_FILE_CONTENTS =
" {\n \"chef\": {\n \"chef_server_url\": \"%{server_url}\",\n \"node_name\": \"%{user}\",\n \"client_key\": \"%{key_file}\"\n },\n \"ssl\": {\n \"verify\": %{ssl_verify}\n }\n }\n".gsub(/^ {8}/, '')
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(keys:, chef_server_url:, username:, ssl_verify:) ⇒ Berkshelf
constructor
A new instance of Berkshelf.
- #unlink ⇒ Object
- #upload(cookbook:, environment:) ⇒ Object
Constructor Details
#initialize(keys:, chef_server_url:, username:, ssl_verify:) ⇒ Berkshelf
21 22 23 24 25 26 |
# File 'lib/formatron/chef/berkshelf.rb', line 21 def initialize(keys:, chef_server_url:, username:, ssl_verify:) @keys = keys @chef_server_url = chef_server_url @username = username @ssl_verify = ssl_verify end |
Instance Method Details
#init ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/formatron/chef/berkshelf.rb', line 28 def init @config_file = Tempfile.new 'formatron-berkshelf-' @config_file.write CONFIG_FILE_CONTENTS % { server_url: @chef_server_url, user: @username, key_file: @keys.user_key, ssl_verify: @ssl_verify } @config_file.close end |
#unlink ⇒ Object
50 51 52 |
# File 'lib/formatron/chef/berkshelf.rb', line 50 def unlink @config_file.unlink unless @config_file.nil? end |
#upload(cookbook:, environment:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/formatron/chef/berkshelf.rb', line 39 def upload(cookbook:, environment:) # rubocop:disable Metrics/LineLength command = "berks install -b #{File.join(cookbook, 'Berksfile')}" fail "failed to download cookbooks for opscode environment: #{environment}" unless Util::Shell.exec command command = "berks upload -c #{@config_file.path} -b #{File.join(cookbook, 'Berksfile')}" fail "failed to upload cookbooks for opscode environment: #{environment}" unless Util::Shell.exec command command = "berks apply #{environment} -c #{@config_file.path} -b #{File.join(cookbook, 'Berksfile.lock')}" fail "failed to apply cookbooks to opscode environment: #{environment}" unless Util::Shell.exec command # rubocop:enable Metrics/LineLength end |