Sha256: 08dd31aa6b3e71b50a712f8d486077c33a53654a428cb86e6ab8a65ada31222e

Contents?: true

Size: 1.91 KB

Versions: 18

Compression:

Stored size: 1.91 KB

Contents

module Ridley
  module BootstrapContext
    # Represents a binding that will be evaluated as an ERB template. When bootstrapping
    # nodes, an instance of this class represents the customizable and necessary configurations
    # needed by the Host in order to install and connect to Chef. By default, this class will be used
    # when SSH is the best way to connect to the node.
    class Unix < BootstrapContext::Base
      attr_reader :sudo

      # @option options [Boolean] :sudo (true)
      #   bootstrap with sudo (default: true)
      def initialize(options = {})
        options = options.reverse_merge(sudo: true)
        @sudo   = options[:sudo]
        super(options)
      end

      # @return [String]
      def boot_command
        cmd = template.evaluate(self)

        if sudo
          cmd = "sudo #{cmd}"
        end

        cmd
      end

      # @return [String]
      def chef_config
        body = <<-CONFIG
  log_level        :info
  log_location     STDOUT
  chef_server_url  "#{server_url}"
  validation_client_name "#{validator_client}"
  CONFIG

        if node_name.present?
          body << %Q{node_name "#{node_name}"\n}
        else
          body << "# Using default node name (fqdn)\n"
        end

        if bootstrap_proxy.present?
          body << %Q{http_proxy        "#{bootstrap_proxy}"\n}
          body << %Q{https_proxy       "#{bootstrap_proxy}"\n}
        end

        if encrypted_data_bag_secret.present?
          body << %Q{encrypted_data_bag_secret "#{bootstrap_directory}/encrypted_data_bag_secret"\n}
        end

        body
      end

      # @return [String]
      def bootstrap_directory
        "/etc/chef"
      end

      # @return [String]
      def chef_run
        "chef-client -j #{bootstrap_directory}/first-boot.json -E #{environment}"
      end

      # @return [String]
      def default_template
        templates_path.join('unix_omnibus.erb').to_s
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ridley-1.2.6 lib/ridley/bootstrap_context/unix.rb
ridley-1.2.5 lib/ridley/bootstrap_context/unix.rb
ridley-1.4.0 lib/ridley/bootstrap_context/unix.rb
ridley-1.3.2 lib/ridley/bootstrap_context/unix.rb
ridley-1.3.1 lib/ridley/bootstrap_context/unix.rb
ridley-1.3.0 lib/ridley/bootstrap_context/unix.rb
ridley-1.0.3 lib/ridley/bootstrap_context/unix.rb
ridley-1.2.4 lib/ridley/bootstrap_context/unix.rb
ridley-1.2.3 lib/ridley/bootstrap_context/unix.rb
ridley-1.2.2 lib/ridley/bootstrap_context/unix.rb
ridley-1.2.1 lib/ridley/bootstrap_context/unix.rb
ridley-1.2.0 lib/ridley/bootstrap_context/unix.rb
ridley-1.1.1 lib/ridley/bootstrap_context/unix.rb
ridley-1.1.0 lib/ridley/bootstrap_context/unix.rb
ridley-1.0.2 lib/ridley/bootstrap_context/unix.rb
ridley-1.0.1 lib/ridley/bootstrap_context/unix.rb
ridley-1.0.0 lib/ridley/bootstrap_context/unix.rb
ridley-1.0.0.rc3 lib/ridley/bootstrap_context/unix.rb