XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Hub Template Debian 11 cloud init network configuration

    Scheduled Pinned Locked Moved Xen Orchestra
    5 Posts 3 Posters 5.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V Offline
      vmpr
      last edited by vmpr

      Hi Team! thanks for your great work 🙂
      I have a question regarding the debian11 hub cloud-init template. maybe @fohdeesha is the right person?

      I am using this network configuration for deployment:

      network:
        version: 1
        config:
          - type: physical
            name: eth0
            subnets:
              - type: static
                address: 172.16.232.93/26
                gateway: 172.16.232.65
                dns_nameservers:
                  - 172.16.232.65
                dns_search:
                  - xx.xxxxxx.xx
      

      The Machine boots and gets an IP from DHCP and installs how it should, but it never changes to the configured IP address until I reboot the machine, but then it comes up with two IP-addresses:

      2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
          link/ether aa:90:ca:c4:15:c2 brd ff:ff:ff:ff:ff:ff
          inet 172.16.232.93/26 brd 172.16.232.127 scope global eth0
             valid_lft forever preferred_lft forever
          inet 172.16.232.121/26 brd 172.16.232.127 scope global secondary dynamic eth0
             valid_lft 541041sec preferred_lft 541041sec
          inet6 fe80::a890:caff:fec4:15c2/64 scope link
             valid_lft forever preferred_lft forever
      

      the one I configured with the YAML and also the DHCP IP address from the first boot.

      I can see these configurations:
      cloud-init network configuration file from YAML config

      root@XXX:~ cat /etc/network/interfaces.d/50-cloud-init
      # This file is generated from information provided by the datasource.  Changes
      # to it will not persist across an instance reboot.  To disable cloud-init's
      # network configuration capabilities, write a file
      # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
      # network: {config: disabled}
      auto lo
      iface lo inet loopback
      
      auto eth0
      iface eth0 inet static
          address 172.16.232.93/26
          dns-nameservers 172.16.232.65
          dns-search qa.oneserv.de
          gateway 172.16.232.65
      

      Debian standard network config file with DHCP enabled:

      root@XXX:~ cat /etc/network/interfaces
      # This file describes the network interfaces available on your system
      # and how to activate them. For more information, see interfaces(5).
      
      source /etc/network/interfaces.d/*
      
      # The loopback network interface
      auto lo
      iface lo inet loopback
      
      # The primary network interface
      allow-hotplug eth0
      iface eth0 inet dhcp
      

      Does anyone know what I have to do to get rid off the DHCP assigned IP address and how I can apply the configured network config instantly without having the DHCP assigned one or without rebooting after the installation?

      And what is the default user password for the debian or root user? i deploy keys so I can access the machine normally but if I have problems with network or sshd then I would like to login via xoa-console but don't have a pw 😞

      cheers, Ringo

      fohdeeshaF 1 Reply Last reply Reply Quote 0
      • olivierlambertO Offline
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by

        Question for @fohdeesha 🙂

        1 Reply Last reply Reply Quote 0
        • fohdeeshaF Offline
          fohdeesha Vates 🪐 Pro Support Team @vmpr
          last edited by

          @vmpr Hi, this is one of cloud-inits many "features" - on debian and debian-like distros, it does not overwrite /etc/network/interfaces - it appends the existing config with a file placed under /etc/network/interfaces.d/ as you noticed - this is cloud-inits design choice. So when Debian's default /etc/network/interfaces file has dhcp configured on eth0, it's going to pull a DHCP address. There's two ways around this. One, you can remove the interface config inside of /etc/network/interfaces - I thought about this briefly when creating the hub templates - then debian would not have its own DHCP address added to your static config. The problem though is users who do not provide their own network config during spin up (which is about 90% of our users) will have a VM spin up with no network config or address at all, which obviously isn't an option.

          The second option is using cloud-inits ability to run commands after spin-up, and use it to run sed or similar to remove the dhcp config out of the /etc/network/interfaces file, then restart the networking service. If you google around you'll find some suggestions about this and the syntax to use (I'm not an expert here). https://cloudinit.readthedocs.io/en/latest/topics/modules.html#runcmd

          As for it taking a reboot for the static IP to be applied, I never experienced that so I can't say what's going on there. As for the default password, there is no passwords for any users on the templates by default for security reasons. You must use a key, or use the runcmd cloud-init param above to run something like echo 'root:mypass' | chpasswd after the first boot to set a password

          V 1 Reply Last reply Reply Quote 0
          • V Offline
            vmpr @fohdeesha
            last edited by

            @fohdeesha thanks for the information, I've added the following to my cloud-init template:

            runcmd:
              # disable dhcp for eth0
              - [ sh, -c, sed -e '/iface eth0 inet dhcp/s/^/#/g' -i /etc/network/interfaces ]
            

            at the end of the installation I have a reboot of the machine anyway so I don't restart the network in between:

            power_state:
             delay: "+2" # minutes
             mode: reboot
             message: rebooting system after cloud-init configurations are finished
             timeout: 120 # seconds
            

            cheers and keep up the good work!
            Ringo

            fohdeeshaF 1 Reply Last reply Reply Quote 2
            • fohdeeshaF Offline
              fohdeesha Vates 🪐 Pro Support Team @vmpr
              last edited by

              @vmpr Great work and example!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post