Class: Formatron::ChefClients

Inherits:
Object
  • Object
show all
Defined in:
lib/formatron/chef_clients.rb

Overview

creates chef clients

Instance Method Summary collapse

Constructor Details

#initialize(directory:, aws:, bucket:, name:, target:, ec2_key:, administrator_name:, administrator_password:, hosted_zone_name:, vpc:, external:, configuration:, databag_secret:) ⇒ ChefClients

rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/formatron/chef_clients.rb', line 7

def initialize(
  directory:,
  aws:,
  bucket:,
  name:,
  target:,
  ec2_key:,
  administrator_name:,
  administrator_password:,
  hosted_zone_name:,
  vpc:,
  external:,
  configuration:,
  databag_secret:
)
  @chef_clients = {}
  if external.nil?
    bastions = Util::VPC.instances :bastion, vpc
    chef_servers = Util::VPC.instances :chef_server, vpc
  else
    bastions = Util::VPC.instances :bastion, external, vpc
    chef_servers = Util::VPC.instances :chef_server, external, vpc
  end
  bastions = Hash[bastions.map { |k, v| [k, v.sub_domain] }]
  chef_servers.each do |key, chef_server|
    @chef_clients[key] = Chef.new(
      directory: directory,
      aws: aws,
      bucket: bucket,
      name: name,
      target: target,
      username: chef_server.username,
      organization: chef_server.organization.short_name,
      ssl_verify: chef_server.ssl_verify,
      chef_sub_domain: chef_server.sub_domain,
      ec2_key: ec2_key,
      administrator_name: administrator_name,
      administrator_password: administrator_password,
      bastions: bastions,
      hosted_zone_name: hosted_zone_name,
      server_stack: chef_server.stack || name,
      guid: chef_server.guid,
      configuration: configuration,
      databag_secret: databag_secret
    )
  end
end

Instance Method Details

#get(key = nil) ⇒ Object

rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize rubocop:enable Metrics/ParameterLists



58
59
60
61
# File 'lib/formatron/chef_clients.rb', line 58

def get(key = nil)
  key ||= @chef_clients.keys[0]
  @chef_clients[key]
end

#initObject



63
64
65
# File 'lib/formatron/chef_clients.rb', line 63

def init
  @chef_clients.values.each(&:init)
end