Sha256: 7503600b7d17b484b343f5a4a3624bb15fe6ccc2aea96c85ca3e9f5d80025030

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'fileutils'

# DeployRubygem - deploy a gem using rake
# Containing a class
module DeployRubygem
  # Using Project to deploy and manage Project
  class ChefNode
    attr_reader :chef_server_url, :nodename, :policyname, :policygroup, :knife_name, :chef_client_key

    def initialize(options)
      @chef_server_url = options['chef_server_url']
      @nodename = options['node_name']
      @policyname = options['policyname']
      @policygroup = options['policygroup']
      @knife_name = options['knife_name']
      @chef_client_key = options['chef_client_key']
    end

    def clientrb
      {
        log_location: '/var/log/chef-client.log',
        chef_server_url: chef_server_url,
        chef_license: 'accept',
        file_cache_path: '/var/chef/cache',
        file_backup_path: '/var/chef/backup',
        node_name: nodename,
        policy_name: policyname,
        policy_group: policygroup
      }.map do |key, value|
        abort("key #{key} need to have a value :: #{value.class}") if value.nil? || value.empty?
        key_pair = [key, "'#{value}'"]
        key_pair.join(' ')
      end.join("\n")
    end

    def read_file(file_path)
      puts "REading file #{file_path}"
      puts File.read(file_path)
      puts "Had read #{File.read(file_path).split('\n').length} lines"
    end

    def boostrap
      extend DeployRubygem

      clientrb_file = '/etc/chef/client.rb'
      clientpem_file = '/etc/chef/client.pem'

      FileUtils.mkdir_p('/etc/chef')

      File.write(clientrb_file, clientrb)
      File.write(clientpem_file, chef_client_key.split('\\n').join("\n"))

      [clientrb_file, clientpem_file].each do |file_path|
        FileUtils.chmod(0o600, file_path)
        # read_file(file_path)
      end

      system(chef_accept_cmd)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deploy_rubygem-0.60.35 lib/deploy_rubygem/chef_node.rb
deploy_rubygem-0.60.34 lib/deploy_rubygem/chef_node.rb