Class: Simp::Cli::Config::Item::HostnameConf
- Inherits:
-
ActionItem
- Object
- Simp::Cli::Config::Item
- ActionItem
- Simp::Cli::Config::Item::HostnameConf
- Defined in:
- lib/simp/cli/config/item/hostname_conf.rb
Instance Attribute Summary
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 ⇒ HostnameConf
constructor
A new instance of HostnameConf.
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 ⇒ HostnameConf
Returns a new instance of HostnameConf.
9 10 11 12 13 14 |
# File 'lib/simp/cli/config/item/hostname_conf.rb', line 9 def initialize super @key = 'hostname::conf' @description = 'action item; configures hostname' @die_on_apply_fail = true end |
Instance Method Details
#apply ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/simp/cli/config/item/hostname_conf.rb', line 16 def apply success = true fqdn = @config_items.fetch( 'hostname' ).value # TODO: should we use this shortname instead of fqdn? hostname = fqdn.split('.').first # copy/pasta'd logic from old simp config # TODO: replace this with 'puppet apply' + network::global say_green ' updating hostname...' if !@silent `hostname #{fqdn}` success = success && $?.success? `sed -i '/HOSTNAME/d' /etc/sysconfig/network` success = success && $?.success? `echo HOSTNAME=#{fqdn} >> /etc/sysconfig/network` success = success && $?.success? # For EL 7 / systemd if File.exist?('/etc/hostname') say_green ' updating /etc/hostname...' File.open('/etc/hostname','w'){|fh| fh.puts(fqdn)} # hostnamectl is required to persist the change under systemd `hostnamectl --static --pretty set-hostname #{fqdn}` success = success && $?.success? end success end |