Class: Simp::Cli::Config::Item::PuppetAutosign
- Inherits:
-
ActionItem
- Object
- Simp::Cli::Config::Item
- ActionItem
- Simp::Cli::Config::Item::PuppetAutosign
- Defined in:
- lib/simp/cli/config/item/puppet_autosign.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 ⇒ PuppetAutosign
constructor
A new instance of PuppetAutosign.
- #os_value ⇒ Object
- #recommended_value ⇒ Object
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, #print_banner, #print_summary, #puppet_value, #query, #query_ask, #query_extras, #query_status, #safe_apply, #say_blue, #say_green, #say_red, #say_yellow, #to_yaml_s, #validate
Constructor Details
#initialize ⇒ PuppetAutosign
Returns a new instance of PuppetAutosign.
9 10 11 12 13 14 |
# File 'lib/simp/cli/config/item/puppet_autosign.rb', line 9 def initialize super @key = 'puppet::autosign' @description = %Q{By default, the only host eligible for autosign is the puppet master.} @file = '/etc/puppet/autosign.conf' end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
8 9 10 |
# File 'lib/simp/cli/config/item/puppet_autosign.rb', line 8 def file @file end |
Instance Method Details
#apply ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/simp/cli/config/item/puppet_autosign.rb', line 48 def apply entries = recommended_value say_green "Updating #{@file}..." if !@silent File.open(@file, 'w') do |file| file.puts "# You should place any hostnames/domains here that you wish to autosign.\n" + "# The most security-conscious method is to list each individual hostname:\n" + "# hosta.your.domain\n" + "# hostb.your.domain\n" + "#\n" + "# Wildcard domains work, but absolutely should NOT be used unless you fully\n" + "# trust your network.\n" + "# *.your.domain\n\n" entries.each do |entry| file.puts(entry) end end end |
#os_value ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/simp/cli/config/item/puppet_autosign.rb', line 16 def os_value # TODO: make this a custom fact? values = Array.new File.readable?(@file) && File.readlines(@file).each do |line| next if line =~ /^(\#|\s*$)/ # if we encounter 'puppet.your.domain' (the default value from a # fresh simp-bootstrap RPM), infer this is a freshly installed system # with no legitimate autosign entries. if line =~ /^puppet.your.domain/ values = [] break end values << line.strip end if values.size == 0 nil else values end end |
#recommended_value ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/simp/cli/config/item/puppet_autosign.rb', line 39 def recommended_value item = os_value if !item item = @config_items.fetch( 'hostname', nil ) item = [ item.value ] if item end item end |