Windows guest VM with cloudbase init

Discussion in 'Proxmox VE: Installation and configuration' started by itvietnam, Oct 27, 2018.

  1. itvietnam

    itvietnam Member

    Joined:
    Aug 11, 2015
    Messages:
    110
    Likes Received:
    3
    Hello,

    Anyone success config IP, computer, inject user password via cloudbase init?

    I tried tuning conf few days but no luck to get it works.
     
  2. Craig St George

    Joined:
    Jul 31, 2018
    Messages:
    41
    Likes Received:
    4
    haha looks like you are doing the same as me from your username you in Vietnam if so we are nearly neighbors as we are in Singapore

    Any way I got a few things to work
    User and password not working
    I get like
    Cannot set the password in the metadata as it is not supported by this service maybe a Clear text one will work

    Networking IP and Gateway is
    DNS servers I don't think are working

    I first thing is you need to change Proxmox
    /usr/share/perl5/PVE/QemuServer/Cloudinit.pm

    change
    run_command([['genisoimage','-iso-level', '3', '-R', '-V', $label, $path],
    e.g add that '-iso-level', '3'
    systemctl restart pvedaemon

    Now the CD will work as long as you set the OS to windows proxmox will use the Configdrive 2

    That is the first part now some things will work
    I m trying to work out the user and pass but this is so Painful
    As I hate windows and so hard to work with
    I also found on the windows server Remove KEY_LOCAL_MACHINE\SOFTWARE Cloudbase Solutions\Cloudbase-Init
    Restart-Service cloudbase-init is you want to reset the init before restarting the maching for testing
    And make sure you have a serial device in your hardware so you can use the term,.js to look at the debug out

    If you can work it out let me know I have spent too much time
     
  3. itvietnam

    itvietnam Member

    Joined:
    Aug 11, 2015
    Messages:
    110
    Likes Received:
    3
    lol, same work here in Vietnam. I (personally) usually move to Singapore every month. May i know your company?

    I will check back cloud-init Windows soon. Thanks,
     
  4. chengkinhung

    chengkinhung New Member

    Joined:
    Feb 11, 2016
    Messages:
    4
    Likes Received:
    0
    Hi, Thanks for your tips. I changed Cloudinit.pm, but only succeed to change IP address, can not change DNS/Hostname, and seems password always change with random one, so after reboot windows will always not able to login again.
     
  5. chengkinhung

    chengkinhung New Member

    Joined:
    Feb 11, 2016
    Messages:
    4
    Likes Received:
    0
    Thanks. I finally succeed to setup IP/Hostname/Password with Windows2016/CoudbaseInit through Proxmox/CloudInit.
    I have to modify the CoudbaseInit python code and Proxmox/CloudInit perl code. Here are the changing I had done:

    (1) Change roxmox/CloudInit perl code to support configdrive2 format(as proxmox default use ncloud format):
    # vi /usr/share/perl5/PVE/QemuServer/Cloudinit.pm
    Code:
    run_command([['genisoimage','-iso-level', '3', '-R', '-V', $label, $path],
    (2) Change roxmox/CloudInit perl code to save cleartext password for windows type VM:
    # vi /usr/share/perl5/PVE/QemuServer/Cloudinit.pm
    Code:
    ...
    +   my $conf = PVE::QemuConfig->load_config($vmid);
    +   my $ostype = $conf->{ostype};
       if (defined(my $cipassword = $param->{cipassword})) {
           # Same logic as in cloud-init (but with the regex fixed...)
    +       if (!(PVE::QemuServer::windows_version($ostype))) {
               $param->{cipassword} = PVE::Tools::encrypt_pw($cipassword)
                   if $cipassword !~ /^\$(?:[156]|2[ay])(\$.+){2}/;
    +       }
    ...
    (3) Change roxmox/CloudInit perl code to add hostname/admin_password fields into meta_data.json
    # vi /usr/share/perl5/PVE/QemuServer/Cloudinit.pm
    Code:
    ...
    sub configdrive2_metadata {
        my ($uuid) = @_;
    +   my ($conf, $vmid, $uuid) = @_;
    +   my ($hostname, $fqdn) = get_hostname_fqdn($conf, $vmid);
    +   my $password = $conf->{cipassword};
    ...
        "uuid": "$uuid",
    +   "hostname": "$hostname",
    +   "admin_pass": "$password",
        "network_config": { "content_path": "/content/0000" }
    ...
    sub generate_configdrive2 {
    ...
    -   my $meta_data = configdrive2_metadata($uuid_str);
    +   my $meta_data = configdrive2_metadata($conf, $vmid, $uuid_str);
    ...
    (4) Change CoudbaseInit python code to disable generate_random_password
    Modify C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\Lib\site-packages\cloudbaseinit\plugins\common\setuserpassword.py and common out the following lines and add "return None" line:
    Code:
    ...
           password, injected = self._get_password(service, shared_data)
           if not password:
               return None
               # LOG.debug('Generating a random user password')
               # maximum_length = osutils.get_maximum_password_length()
               # password = osutils.generate_random_password(
               #    maximum_length)
    ...
     
  6. Craig St George

    Joined:
    Jul 31, 2018
    Messages:
    41
    Likes Received:
    4
    Thanks for that also now we have lost of options lol

    you should not have needed to change the cloudbase init just set
    like
    username=Admin
    groups=Administrators

    inject_user_password=true
    there is another variable also
    • first_logon_behaviour
    first_logon_behaviour=no should do it

    also your DNS may not be working unless you changed to
    dns-nameservers and they but be under the interface settings for that interface eg like this


    Code:
     
    my ($addr, $mask) = split_ip4($net->{ip});
                    $content .= "iface $id inet static\n";
                    $content .= "        address $addr\n";
                    $content .= "        netmask $mask\n";
                    $content .= "        gateway $net->{gw}\n" if $net->{gw};
                    $content .= "        dns-nameservers $nameservers\n";
    
     
  7. chengkinhung

    chengkinhung New Member

    Joined:
    Feb 11, 2016
    Messages:
    4
    Likes Received:
    0
    @Craig St George
    Hi, thanks.

    In my case, the DNS is not important, i can setup in the windows template directly, however changing password of Administrator is my main goal, that also mens I need to set first_logon_behaviour=no. Disable the generate_random_password is very very important for using cloudbase-init in windows, as any time the cloudbase-init can not find the password, they will set the password with a random password, there is not way to know this random password unless you are using openstack's HttpService, and I found the both Proxmox/Cloud-init and Windows/Cloudbase-Init are not quite stable, cause my windows VM fail to login due to the Administrator been set to random password.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice