[Ovirt-devel] [PATCH server] verify hostname is not on the loopback entry in /etc/hosts

David Lutterkort lutter at redhat.com
Thu Apr 2 21:44:13 UTC 2009


On Thu, 2009-04-02 at 11:44 -0400, Joey Boggs wrote:
> Trying to get this working on a test file but running into:   tundefined 
> method `init' for Augeas:Class (NoMethodError)

I should have tried it first ;) The method in question is Augeas::open.

This works (with one crazy match instead of a loop calling aug.get ;):

        require 'augeas'
        
        hostname="host.example.com"
        
        aug = Augeas::open(nil, nil, 0)
        bad_entries = aug.match("/files/etc/hosts/*/*[../ipaddr = '127.0.0.1'][label() = 'alias' or label() = 'canonical'][ . = '#{hostname}']")
        
        if bad_entries.size > 0
            puts "Hostname #{hostname} mentioned on the line for 127.0.0.1"
            should_fix = false # Change to prompt user
            if should_fix
                bad_entries.each { |e| aug.rm(e) }
            end
        end

David





More information about the ovirt-devel mailing list