centos 8 cloud image + not changing cloud config hostname

    • coud-init setup for centos 8

    what is the equivalent of this command or step for creating centos 8 cloud image for use with XOA as seen in this tutorial https://xen-orchestra.com/blog/debian-cloud-template-for-xenserver/?

    dpkg-reconfigure cloud-init

    I have done everything else but that step is what remains

    Here are logs from /var/log/cloud-init.log

    2019-12-22 00:55:05,752 - util.py[DEBUG]: Restoring selinux mode for /var/log/cloud-init.log (recursive=False)
    2019-12-22 00:55:05,754 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance/boot-finished
    2019-12-22 00:55:05,755 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/data/no-net
    2019-12-22 00:55:05,755 - handlers.py[DEBUG]: start: init-local/check-cache: attempting to read from cache [check]
    2019-12-22 00:55:05,756 - util.py[DEBUG]: Reading from /var/lib/cloud/instance/obj.pkl (quiet=False)
    2019-12-22 00:55:05,756 - stages.py[DEBUG]: no cache found
    2019-12-22 00:55:05,757 - handlers.py[DEBUG]: finish: init-local/check-cache: SUCCESS: no cache found
    2019-12-22 00:55:05,757 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance
    2019-12-22 00:55:05,776 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.rhel.Distro'>
    2019-12-22 00:55:05,777 - __init__.py[DEBUG]: Looking for data source in: ['NoCloud', 'ConfigDrive', 'OpenNebula', 'DigitalOcean', 'Azure', 'AltCloud', 'OVF', 'MAAS', 'GCE', 'OpenStack', 'AliYun', 'Ec2', 'CloudSigma', 'CloudStack', 'SmartOS', 'Bigstep', 'Scaleway', 'Hetzner', 'IBMCloud', 'Oracle', 'None'], via packages ['', 'cloudinit.sources'] that matches dependencies ['FILESYSTEM']
    2019-12-22 00:55:05,926 - util.py[DEBUG]: Reading from /etc/os-release (quiet=False)
    2019-12-22 00:55:05,926 - util.py[DEBUG]: Read 420 bytes from /etc/os-release
    2019-12-22 00:55:06,072 - __init__.py[DEBUG]: Searching for local data source in: ['DataSourceNoCloud', 'DataSourceConfigDrive', 'DataSourceOpenNebula', 'DataSourceDigitalOcean', 'DataSourceAzure', 'DataSourceOVF', 'DataSourceOpenStackLocal', 'DataSourceEc2Local', 'DataSourceCloudSigma', 'DataSourceSmartOS', 'DataSourceScaleway', 'DataSourceHetzner', 'DataSourceIBMCloud', 'DataSourceOracle']
    2019-12-22 00:55:06,073 - handlers.py[DEBUG]: start: init-local/search-NoCloud: searching for local data from DataSourceNoCloud
    2019-12-22 00:55:06,073 - __init__.py[DEBUG]: Seeing if we can get any data from <class 'cloudinit.sources.DataSourceNoCloud.DataSourceNoCloud'>
    2019-12-22 00:55:06,074 - __init__.py[DEBUG]: Update datasource metadata and network config due to events: New instance first boot
    2019-12-22 00:55:06,074 - util.py[DEBUG]: Running command ['systemd-detect-virt', '--quiet', '--container'] with allow...skipping...
    requency once-per-instance
    2019-12-22 01:25:43,247 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_phone_home - wb: [644] 25 bytes
    2019-12-22 01:25:43,248 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_phone_home (recursive=False)
    2019-12-22 01:25:43,252 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_phone_home (recursive=False)
    2019-12-22 01:25:43,253 - helpers.py[DEBUG]: Running config-phone-home using lock (<FileLock using file '/var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_phone_home'>)
    2019-12-22 01:25:43,253 - cc_phone_home.py[DEBUG]: Skipping module named phone-home, no 'phone_home' configuration found
    2019-12-22 01:25:43,253 - handlers.py[DEBUG]: finish: modules-final/config-phone-home: SUCCESS: config-phone-home ran successfully
    2019-12-22 01:25:43,253 - stages.py[DEBUG]: Running module final-message (<module 'cloudinit.config.cc_final_message' from '/usr/lib/python3.6/site-packages/cloudinit/config/cc_final_message.py'>) with frequency always
    2019-12-22 01:25:43,253 - handlers.py[DEBUG]: start: modules-final/config-final-message: running config-final-message with frequency always
    2019-12-22 01:25:43,254 - helpers.py[DEBUG]: Running config-final-message using lock (<cloudinit.helpers.DummyLock object at 0x7f47cf9a3dd8>)
    2019-12-22 01:25:43,254 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
    2019-12-22 01:25:43,254 - util.py[DEBUG]: Read 12 bytes from /proc/uptime
    2019-12-22 01:25:43,267 - util.py[DEBUG]: Cloud-init v. 18.5 finished at Sun, 22 Dec 2019 01:25:43 +0000. Datasource DataSourceConfigDrive [net,ver=2][source=/dev/xvdc].  Up 38.53 seconds
    2019-12-22 01:25:43,267 - util.py[DEBUG]: Writing to /var/lib/cloud/instance/boot-finished - wb: [644] 50 bytes
    2019-12-22 01:25:43,268 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/boot-finished (recursive=False)
    2019-12-22 01:25:43,269 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/boot-finished (recursive=False)
    2019-12-22 01:25:43,270 - handlers.py[DEBUG]: finish: modules-final/config-final-message: SUCCESS: config-final-message ran successfully
    2019-12-22 01:25:43,270 - stages.py[DEBUG]: Running module power-state-change (<module 'cloudinit.config.cc_power_state_change' from '/usr/lib/python3.6/site-packages/cloudinit/config/cc_power_state_change.py'>) with frequency once-per-instance
    2019-12-22 01:25:43,270 - handlers.py[DEBUG]: start: modules-final/config-power-state-change: running config-power-state-change with frequency once-per-instance
    2019-12-22 01:25:43,271 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_power_state_change - wb: [644] 25 bytes
    2019-12-22 01:25:43,272 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_power_state_change (recursive=False)
    2019-12-22 01:25:43,273 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_power_state_change (recursive=False)
    2019-12-22 01:25:43,273 - helpers.py[DEBUG]: Running config-power-state-change using lock (<FileLock using file '/var/lib/cloud/instances/644f20b5-5b83-dd11-97e5-10f849181b0e/sem/config_power_state_change'>)
    2019-12-22 01:25:43,274 - cc_power_state_change.py[DEBUG]: no power_state provided. doing nothing
    2019-12-22 01:25:43,274 - handlers.py[DEBUG]: finish: modules-final/config-power-state-change: SUCCESS: config-power-state-change ran successfully
    2019-12-22 01:25:43,274 - main.py[DEBUG]: Ran 10 modules with 0 failures
    2019-12-22 01:25:43,275 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/result.json' => '../../var/lib/cloud/data/result.json'
    2019-12-22 01:25:43,276 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
    2019-12-22 01:25:43,278 - util.py[DEBUG]: Read 12 bytes from /proc/uptime
    2019-12-22 01:25:43,278 - util.py[DEBUG]: cloud-init mode 'modules' took 0.408 seconds (0.41)
    2019-12-22 01:25:43,278 - handlers.py[DEBUG]: finish: modules-final: SUCCESS: running modules for final
    • changing hostname via cloud config not working

    cloudinit is not changing the hostname i passed in the cloud config file when it creates new VM from a cloud image. Is there a place to check to make sure i have correct settings?

    here is what i have in my

    preserve_hostname: false
     - disk_setup
     - migrator
     - bootcmd
     - write-files
     - growpart
     - resizefs
     - set_hostname
     - update_hostname
     - update_etc_hosts
     - rsyslog
     - users-groups
     - ssh

    but yet it is not modifying the hostname on centos 8 cloud image i created

  • is this step really needed for the Debian/Ubuntu cloud images?
    $ dpkg-reconfigure cloud-init

    if yes, then what is the use of that? and why is it needed?
    and why was this not needed for centos 8 cloud image? didn't have to run this command and the centos 8 cloud image works fine

    Also if yes, then is this correct selection?


  • XCP-ng Team

    1. dpkg is a Debian/Ubuntu package management thing. CentOS doesn't use dpkg but rpm.
    2. This was needed on old Debian/Ubuntu to tell to use the "right" config drive option. You can setup this in the Cloudinit config file directly. Take time to read carefully CloudInit configuration, it's not great but still a good start 🙂 https://cloudinit.readthedocs.io/en/latest/

    @fohdeesha might be able to give you some hints too 🙂

  • @olivierlambert

    yeah so far i got everything to work on centos 8 cloud image
    only thing not working is the hostname changing..the hostname is not working
    creating new VMs with a different hostname does not work and keeps hostname of the template

  • XCP-ng Team

    paste exactly what you're entering into the two cloud-init config boxes in XO

  • @fohdeesha

    here is what is in my XOA cloud config file

    hostname: host
      - ssh-rsa user1@host1
      - ssh-rsa user2@host2
      - ssh-rsa user3@host3

    redacted the ssh keys ofcourse but thats all am doing..just change hostname and add SSH keys..thats it

    the SSH keys get added fine for centos 8, but hostname not working

  • XCP-ng Team

    that looks good, and the fact that the VM is properly using the new SSH keys means the config data (and config drive) is properly being formatted and passed to the VM, and the VM is picking it up and using it - which rules out XOA as the source of the issue. It looks like CentOS is choosing to ignore the hostname config, I'm not an experienced centOS user so I have no idea.

  • @fohdeesha

    yeah for the centos 8 i think am fine with that
    the ubuntu one does not work at all
    i have my full cloud init config posted here https://xcp-ng.org/forum/topic/2387/how-to-create-single-partition-on-ubuntu-18-04-for-cloud-image/9

  • Maybe a bit late, but I have the same Problem in centos8!

    I suppose the reason is a bug in the cloud-init version in Centos8 because of this message:

    Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/cloudinit/sources/__init__.py", line 733, in find_source
        if s.update_metadata([EventType.BOOT_NEW_INSTANCE]):
      File "/usr/lib/python3.6/site-packages/cloudinit/sources/__init__.py", line 622, in update_metadata
        result = self.get_data()
      File "/usr/lib/python3.6/site-packages/cloudinit/sources/__init__.py", line 256, in get_data
        return_value = self._get_data()
      File "/usr/lib/python3.6/site-packages/cloudinit/sources/DataSourceNoCloud.py", line 126, in _get_data
        mydata = _merge_new_seed(mydata, seeded)
      File "/usr/lib/python3.6/site-packages/cloudinit/sources/DataSourceNoCloud.py", line 353, in _merge_new_seed
      File "/usr/lib/python3.6/site-packages/cloudinit/sources/DataSourceNoCloud.py", line 324, in _maybe_remove_top_network
        network_val = cfg.get('network', nullval)
    AttributeError: 'NoneType' object has no attribute 'get'

    So the trick is, you have to add some content into the network-config
    (It doesn't matter if you disable the network config in your cloud.cfg):

    version: 1

    And then you can set the hostname in the user-data with

    fqdn: {name}.localdomain.local


  • XCP-ng Team

    Thanks for sharing.

Log in to reply

XCP-ng Pro Support

XCP-ng Pro Support