Class: BeakerAnswers::Version20162 Private

Inherits:
Version20161 show all
Defined in:
lib/beaker-answers/versions/version20162.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class provides answer file information for PE version 2016.2

Direct Known Subclasses

Version20163

Constant Summary

Constants inherited from Answers

Answers::DEFAULT_ANSWERS, Answers::DEFAULT_FORMAT, Answers::DEFAULT_HIERA_ANSWERS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Version30

#host_answers

Methods inherited from Answers

#answer_for, #answer_string, #answers, create, #get_defaults_or_answers, #initialize, #only_host_with_role, supported_upgrade_versions, supported_versions

Constructor Details

This class inherits a constructor from BeakerAnswers::Answers

Class Method Details

.pe_version_matcherObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The version of PE that this set of answers is appropriate for



9
10
11
# File 'lib/beaker-answers/versions/version20162.rb', line 9

def self.pe_version_matcher
  /\A2016\.2/
end

Instance Method Details

#answer_hieraString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This converts a data hash provided by answers, and returns a Puppet Enterprise compatible hiera config file ready for use.

end

Examples:

Generating an answer file for a series of hosts

hosts.each do |host|
  answers = Beaker::Answers.new("2.0", hosts, "master")
  create_remote_file host, "/mypath/answer", answers.answer_hiera

Returns:

  • (String)

    a string of parseable hocon



99
100
101
102
103
104
# File 'lib/beaker-answers/versions/version20162.rb', line 99

def answer_hiera
  # Render pretty JSON, because it is a subset of HOCON
  json = JSON.pretty_generate(answers)
  hocon = Hocon::Parser::ConfigDocumentFactory.parse_string(json)
  hocon.render
end

#generate_answersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
# File 'lib/beaker-answers/versions/version20162.rb', line 13

def generate_answers
  the_answers = super

  return the_answers if @options[:masterless]

  return generate_hiera_config
end

#generate_bash_answers(answers) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/beaker-answers/versions/version20162.rb', line 21

def generate_bash_answers(answers)
  console = only_host_with_role(@hosts, 'dashboard')

  # To allow SSL cert based auth in the new installer while maintaining the legacy
  # bash script, the console node now needs to know about the orchestrator database user
  # and name if they are specified to be non default
  orchestrator_db = {
    :q_orchestrator_database_name     => answer_for(@options, :q_orchestrator_database_name),
    :q_orchestrator_database_user     => answer_for(@options, :q_orchestrator_database_user),
  }

  answers[console.name].merge!(orchestrator_db)

  return answers
end

#generate_hiera_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/beaker-answers/versions/version20162.rb', line 37

def generate_hiera_config
  # The hiera answer file format will get all answers, regardless of role
  # it is being installed on
  hiera_hash = {}

  # Add the correct host values for this beaker configuration
  hiera_hash.merge!(hiera_host_config)

  hiera_hash.merge!(get_defaults_or_answers([
    "console_admin_password",
    "puppet_enterprise::use_application_services",
  ]))

  hiera_hash.merge!(hiera_db_config)

  # Override with any values provided in the :answers key hash
  if @options[:answers]
    if @options[:answers].keys.any? { |k| k.to_s.start_with?('q_') }
      raise(TypeError, "q_ answers are not supported when using the hiera answers format")
    else
      hiera_hash.merge!(flatten_keys_to_joined_string(@options[:answers]))
    end
  end

  return hiera_hash
end

#hiera_db_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/beaker-answers/versions/version20162.rb', line 69

def hiera_db_config
  ns = "puppet_enterprise"
  defaults_to_set = []

  # Set database users only if we are upgrading from < 2016.2.0; necessary
  # because BeakerAnswers sets database user to non-default values in
  # earlier versions.
  if @options[:include_legacy_database_defaults]
    # Database names/users. Required for password and cert-based auth
    defaults_to_set += [
      "#{ns}::puppetdb_database_user",
      "#{ns}::classifier_database_user",
      "#{ns}::activity_database_user",
      "#{ns}::rbac_database_user",
      "#{ns}::orchestrator_database_user",
    ]
  end

  get_defaults_or_answers(defaults_to_set)
end

#hiera_host_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
67
# File 'lib/beaker-answers/versions/version20162.rb', line 64

def hiera_host_config
  pe_conf = BeakerAnswers::PeConf.new(@hosts, '1.0')
  pe_conf.configuration_hash
end

#installer_configuration_string(host) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



106
107
108
# File 'lib/beaker-answers/versions/version20162.rb', line 106

def installer_configuration_string(host)
  answer_hiera
end