cloud-init and hosts files

kifeo

Well-Known Member
Oct 28, 2019
112
12
58
Hi,

I created a debian vm with cloud-init, everything is working fine.

with the command 'qm cloudinit dump <vmid> user' I could see :
manage_etc_hosts: true

This settings overwrites the changes made in the /etc/hosts file, and thus breaks my applications setup.

the reference of this is here :
https://cloudinit.readthedocs.io/en/latest/topics/modules.html#update-etc-hosts


Could someone tell me how to configure this ?

Regards,
Thomas.
 
Last edited:
Sorry I did not read the banner of /etc/hosts :

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
 
But this does not work unfortunately ...

I did workaround by modifying the template.

Any ideas ?
 
Last edited:
Maybe this is not relevant anymore, but according to the mentioned documentation,
Management of the hosts file is controlled using manage_etc_hosts. If this is set to false, cloud-init will not manage the hosts file at all. This is the default behavior.

When I first set Proxmox to use Cloud Init with User, Password, DNS Domain, DNS server and IP Config, it did override my "hosts" configuration after all.
I'm not sure if Proxmox changed the default behavior after configuring these parameters, but it sure wiped my "hosts" file after rebooting the VM.
To fix that, I edited the "/etc/cloud/cloud.cfg" file and commented the "- update_etc_hosts" module line.


YAML:
# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - disk_setup
 - mounts
 - set_hostname
 - update_hostname
 - ca-certs
 - rsyslog
 - users-groups
 - ssh
# - update_etc_hosts

That resolved my issue.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!