Class: Simp::Cli::Config::Item::RemoveLdapFromHiera
- Inherits:
-
ActionItem
- Object
- Simp::Cli::Config::Item
- ActionItem
- Simp::Cli::Config::Item::RemoveLdapFromHiera
- Defined in:
- lib/simp/cli/config/item/remove_ldap_from_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
-
#initialize ⇒ RemoveLdapFromHiera
constructor
A new instance of RemoveLdapFromHiera.
- #strip_line?(line) ⇒ Boolean
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 ⇒ RemoveLdapFromHiera
Returns a new instance of RemoveLdapFromHiera.
11 12 13 14 15 16 17 |
# File 'lib/simp/cli/config/item/remove_ldap_from_hiera.rb', line 11 def initialize super @key = 'puppet::remove_ldap_from_hiera' @description = %Q{Removes any ldap classes from 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/remove_ldap_from_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 37 38 39 40 |
# File 'lib/simp/cli/config/item/remove_ldap_from_hiera.rb', line 19 def apply success = true fqdn = @config_items.fetch( 'hostname' ).value file = File.join( @dir, "#{fqdn}.yaml") say_green 'Removing ldap classes from the <domain>.yaml file' if !@silent if File.exists?(file) lines = File.open(file,'r').readlines File.open(file, 'w') do |f| lines.each do |line| line.chomp! f.puts line if !strip_line?(line) end end else success = false say_yellow "WARNING: file not found: #{file}" end success end |
#strip_line?(line) ⇒ Boolean
43 44 45 |
# File 'lib/simp/cli/config/item/remove_ldap_from_hiera.rb', line 43 def strip_line?( line ) (line =~ /^\s*-\s+(([a-z_:'"]*::)*(open)*ldap|(open)*ldap[a-z_:'"]*)/m) ? true : false end |