Sha256: fde0341205daecfadc9823754c344014023062d9a5b350dd376dea038704d7bb

Contents?: true

Size: 1.43 KB

Versions: 107

Compression:

Stored size: 1.43 KB

Contents

require 'puppet/provider/parsedfile'

hosts = nil
case Facter.value(:osfamily)
when "Solaris"; hosts = "/etc/inet/hosts"
when "windows"
  require 'win32/resolv'
  hosts = Win32::Resolv.get_hosts_path
else
  hosts = "/etc/hosts"
end


Puppet::Type.type(:host).provide(:parsed,:parent => Puppet::Provider::ParsedFile,
  :default_target => hosts,:filetype => :flat) do
  confine :exists => hosts

  text_line :comment, :match => /^#/
  text_line :blank, :match => /^\s*$/

  record_line :parsed, :fields => %w{ip name host_aliases comment},
    :optional => %w{host_aliases comment},
    :match    => /^(\S+)\s+(\S+)\s*(.*?)?(?:\s*#\s*(.*))?$/,
    :post_parse => proc { |hash|
      # An absent comment should match "comment => ''"
      hash[:comment] = '' if hash[:comment].nil? or hash[:comment] == :absent
      unless hash[:host_aliases].nil? or hash[:host_aliases] == :absent
        hash[:host_aliases].gsub!(/\s+/,' ') # Change delimiter
      end
    },
    :to_line  => proc { |hash|
      [:ip, :name].each do |n|
        raise ArgumentError, "#{n} is a required attribute for hosts" unless hash[n] and hash[n] != :absent
      end
      str = "#{hash[:ip]}\t#{hash[:name]}"
      if hash.include? :host_aliases and !hash[:host_aliases].nil? and hash[:host_aliases] != :absent
        str += "\t#{hash[:host_aliases]}"
      end
      if hash.include? :comment and !hash[:comment].empty?
        str += "\t# #{hash[:comment]}"
      end
      str
    }
end

Version data entries

107 entries across 107 versions & 3 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-3.8.7 lib/puppet/provider/host/parsed.rb
puppet-3.8.7-x86-mingw32 lib/puppet/provider/host/parsed.rb
puppet-3.8.7-x64-mingw32 lib/puppet/provider/host/parsed.rb
puppet-3.8.6 lib/puppet/provider/host/parsed.rb
puppet-3.8.6-x86-mingw32 lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-3.8.6-x64-mingw32 lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-3.8.5 lib/puppet/provider/host/parsed.rb
puppet-3.8.5-x86-mingw32 lib/puppet/provider/host/parsed.rb
puppet-3.8.5-x64-mingw32 lib/puppet/provider/host/parsed.rb
puppet-3.8.4 lib/puppet/provider/host/parsed.rb
puppet-3.8.4-x86-mingw32 lib/puppet/provider/host/parsed.rb
puppet-3.8.4-x64-mingw32 lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/provider/host/parsed.rb