Sha256: 6d961c5b8449583c57eda6617d1d460ee0502ce1eea3f6f504a011d0d99d4525

Contents?: true

Size: 1.44 KB

Versions: 42

Compression:

Stored size: 1.44 KB

Contents

require 'puppet/provider/parsedfile'

hosts = nil
case Facter.value(:operatingsystem)
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

42 entries across 42 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/provider/host/parsed.rb
puppet-parse-0.1.3 lib/vendor/puppet/provider/host/parsed.rb
puppet-parse-0.1.2 lib/vendor/puppet/provider/host/parsed.rb
puppet-parse-0.1.1 lib/vendor/puppet/provider/host/parsed.rb
puppet-2.7.26 lib/puppet/provider/host/parsed.rb
puppet-2.7.25 lib/puppet/provider/host/parsed.rb
puppet-2.7.24 lib/puppet/provider/host/parsed.rb
puppet-2.7.23 lib/puppet/provider/host/parsed.rb
puppet-2.7.22 lib/puppet/provider/host/parsed.rb
puppet-parse-0.1.0 lib/vendor/puppet/provider/host/parsed.rb
puppet-parse-0.0.6 lib/vendor/puppet/provider/host/parsed.rb
puppet-2.7.21 lib/puppet/provider/host/parsed.rb
puppet-parse-0.0.5 lib/vendor/puppet/provider/host/parsed.rb
puppet-parse-0.0.4 lib/vendor/puppet/provider/host/parsed.rb
puppet-parse-0.0.2 lib/vendor/puppet/provider/host/parsed.rb
puppet-2.7.20 lib/puppet/provider/host/parsed.rb
puppet-2.7.20.rc1 lib/puppet/provider/host/parsed.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/provider/host/parsed.rb
puppet-2.7.19 lib/puppet/provider/host/parsed.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/provider/host/parsed.rb