Class: Simp::Cli::Config::Item::AddLdapToHiera

Inherits:
ActionItem show all
Defined in:
lib/simp/cli/config/item/add_ldap_to_hiera.rb

Instance Attribute Summary collapse

Attributes inherited from Simp::Cli::Config::Item

#allow_user_apply, #config_items, #description, #die_on_apply_fail, #fact, #fail_on_missing_answer, #key, #next_items_tree, #silent, #skip_apply, #skip_query, #skip_yaml, #value

Instance Method Summary collapse

Methods inherited from ActionItem

#query, #to_yaml_s, #validate

Methods included from SafeApplying

#safe_apply

Methods inherited from Simp::Cli::Config::Item

#default_value, #highline_question_type, #next_items, #not_valid_message, #os_value, #print_banner, #print_summary, #puppet_value, #query, #query_ask, #query_extras, #query_status, #recommended_value, #safe_apply, #say_blue, #say_green, #say_red, #say_yellow, #to_yaml_s, #validate

Constructor Details

#initializeAddLdapToHiera

Returns a new instance of AddLdapToHiera.



11
12
13
14
15
16
17
# File 'lib/simp/cli/config/item/add_ldap_to_hiera.rb', line 11

def initialize
  super
  @key         = 'puppet::add_ldap_to_hiera'
  @description = %Q{Adds simp::ldap_server to hieradata/hosts/puppet.your.domain.yaml (apply-only; noop).}
  @dir         = "/etc/puppet/environments/simp/hieradata/hosts"
  @file        = nil
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



9
10
11
# File 'lib/simp/cli/config/item/add_ldap_to_hiera.rb', line 9

def dir
  @dir
end

Instance Method Details

#applyObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/simp/cli/config/item/add_ldap_to_hiera.rb', line 19

def apply
  success = true
  fqdn    = @config_items.fetch( 'hostname' ).value
  file    = File.join( @dir, "#{fqdn}.yaml")

  say_green 'Adding simp::ldap_server to the <domain>.yaml file' if !@silent

  if File.exists?(file)
    success = true
    yaml = File.open(file, "a") do |f|
      f.puts "  - 'simp::ldap_server'"
    end
  else
    success = false
    say_yellow "WARNING: file not found: #{file}"
  end
  success
end

#contains_ldap?(line) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/simp/cli/config/item/add_ldap_to_hiera.rb', line 39

def contains_ldap?( line )
  (line =~ /^\s*-\s+(([a-z_:'"]*::)*(open)*ldap|(open)*ldap[a-z_:'"]*)/m) ? true : false
end