Class: Simp::Cli::Config::Item::RenameFqdnYaml
- Inherits:
-
ActionItem
- Object
- Simp::Cli::Config::Item
- ActionItem
- Simp::Cli::Config::Item::RenameFqdnYaml
- Defined in:
- lib/simp/cli/config/item/rename_fqdn_yaml.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
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 ⇒ RenameFqdnYaml
constructor
A new instance of RenameFqdnYaml.
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 ⇒ RenameFqdnYaml
Returns a new instance of RenameFqdnYaml.
12 13 14 15 16 17 |
# File 'lib/simp/cli/config/item/rename_fqdn_yaml.rb', line 12 def initialize super @key = 'puppet::rename_fqdn_yaml' @description = %Q{Renames hieradata/hosts/puppet.your.domain.yaml (apply-only; noop).} @file = '/etc/puppet/environments/simp/hieradata/hosts/puppet.your.domain.yaml' end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
10 11 12 |
# File 'lib/simp/cli/config/item/rename_fqdn_yaml.rb', line 10 def file @file 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 |
# File 'lib/simp/cli/config/item/rename_fqdn_yaml.rb', line 19 def apply result = true fqdn = @config_items.fetch( 'hostname' ).value new_file = File.join( File.dirname( @file ), "#{fqdn}.yaml" ) say_green 'Moving default <domain>.yaml file' if !@silent if File.exists?(@file) if File.exists?( new_file ) result = false diff = `diff #{new_file} #{@file}` say_yellow "WARNING: #{File.basename( new_file )} exists, but the content differs from the original system content. Review and consider updating:\n#{diff}" if !diff.empty? else File.rename( @file, new_file ) end else result = false say_yellow "WARNING: file not found: #{@file}" end true end |