def apply
@applied_status = :failed
@fqdn = get_item( 'cli::network::hostname' ).value
debug( 'Updating hostname' )
success = execute("hostname #{@fqdn}")
if (success)
debug( 'Updating /etc/sysconfig/network' )
success = success && execute("sed -i '/HOSTNAME/d' /etc/sysconfig/network")
success = success && execute("echo HOSTNAME=#{@fqdn} >> /etc/sysconfig/network")
end
if (success)
debug( 'Updating /etc/hostname' )
begin
File.open('/etc/hostname','w'){|fh| fh.puts(@fqdn)}
rescue Errno::EACCES
success = false
end
end
if success && ( get_item( 'cli::network::dhcp' ).value == 'dhcp' )
interface = get_item( 'cli::network::interface' ).value
debug( "Restarting #{interface} interface to update domain info" )
show_wait_spinner {
success = success && execute("/sbin/ifdown #{interface}; /sbin/ifup #{interface} && wait && sleep 10")
}
Facter.clear
end
@applied_status = :succeeded if (success)
end