Ask Your Question

Ubuntu cloud image: /etc/hosts file error

asked 2015-12-03 14:49:58 -0500

raff gravatar image

Hello everyone, i'm trying to launch an ubuntu cloud image, but i've seen that the /etc/hosts file doesn't contains my hostname. I need that the hostname is setted during the cloud-init, so not a manually configuration after starting ubuntu. Of course this problem push to the "sudo: unable to resolve host" problem. How to solve it?

I have setted in my OpenStack network the google dns in order to allow the external communication (for cloud-init phase), it could be a problem?

edit retag flag offensive close merge delete


I have the same problem (Kilo) with 14.04 and 16.04 beta Ubuntu guests. Although /etc/hosts is easily fixed, automation failure is annoying! I'm using the OpenDNS svr so I don't think it's anything to do with that. Workaround:

sxc731 gravatar imagesxc731 ( 2016-04-05 13:34:24 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-22 18:35:20 -0500

etank gravatar image

According to ( if manage_etc_hosts is false then the template is not applied to /etc/hosts. I tested using virt-edit today to set this to true and it appeared to work in a quick test. I created a new ubuntu 16.04 vm using the modified image and sudo commands did not hang.

The virt-edit command looked like:

virt-edit -a xenial-server-cloudimg-amd64-disk1.img /etc/cloud/cloud.cfg

Just added this near the top of the file:

manage_etc_hosts: true

Not sure if that is the correct thing to do or not though. Comparing the cloud config to Fedora and Centos based images the manage_etc_hosts is not in those files yet sudo works great on them.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2015-12-03 14:49:58 -0500

Seen: 1,448 times

Last updated: Dec 03 '15