Class: Simp::Cli::Config::Item::DNSServers

Inherits:
ListItem show all
Defined in:
lib/simp/cli/config/item/dns_servers.rb

Instance Attribute Summary collapse

Attributes inherited from ListItem

#allow_empty_list

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

Methods inherited from ListItem

#highline_question_type, #not_valid_message, #query_extras, #validate

Methods inherited from Simp::Cli::Config::Item

#apply, #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

#initializeDNSServers

Returns a new instance of DNSServers.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simp/cli/config/item/dns_servers.rb', line 10

def initialize
  super
  @key         = 'dns::servers'
  @description = %Q{A list of DNS servers for the managed hosts.

    If the first entry of this list is set to '127.0.0.1', then
    all clients will configure themselves as caching DNS servers
    pointing to the other entries in the list.

    If you have a system that's including the 'named' class and
    is *not* in this list, then you'll need to set a variable at
    the top of that node entry called $named_server to 'true'.
    This will get around the convenience logic that was put in
    place to handle the caching entries and will not attempt to
    convert your system to a caching DNS server. You'll know
    that you have this situation if you end up with a duplicate
    definition for File['/etc/named.conf'].}.gsub(/^ +/, '')
  @file = '/etc/resolv.conf'
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/simp/cli/config/item/dns_servers.rb', line 9

def file
  @file
end

Instance Method Details

#os_valueObject



30
31
32
33
# File 'lib/simp/cli/config/item/dns_servers.rb', line 30

def os_value
  # TODO: make this a custom fact?
  File.readlines( @file ).select{ |x| x =~ /^nameserver\s+/ }.map{ |x| x.gsub( /nameserver\s+(.*)\s*/, '\\1' ) }
end

recommend:

- os_value  when present, or:
- ipaddress when present, or:
- a must-change value


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/simp/cli/config/item/dns_servers.rb', line 39

def recommended_value
  os = os_value
  if os.empty?
    if ip = @config_items.fetch( 'ipaddress', nil )
      [ip.value]
    else
      ['8.8.8.8 (change this)']
    end
  else
    os
  end
end

#validate_item(item) ⇒ Object

Each DNS server should be a valid IP address



53
54
55
# File 'lib/simp/cli/config/item/dns_servers.rb', line 53

def validate_item item
  Simp::Cli::Config::Utils.validate_ip item
end