Class: Simp::Cli::Config::Item::AddLdapToHiera
- Inherits:
-
ActionItem
- Object
- Simp::Cli::Config::Item
- ActionItem
- Simp::Cli::Config::Item::AddLdapToHiera
- Defined in:
- lib/simp/cli/config/item/add_ldap_to_hiera.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
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
- #apply ⇒ Object
- #contains_ldap?(line) ⇒ Boolean
-
#initialize ⇒ AddLdapToHiera
constructor
A new instance of AddLdapToHiera.
Methods inherited from ActionItem
Methods included from SafeApplying
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
#initialize ⇒ AddLdapToHiera
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
#dir ⇒ Object
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
#apply ⇒ Object
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
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 |