]> git.proxmox.com Git - qemu-server.git/commitdiff
cloud-init: add ciuser and cipassword config options
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 6 Mar 2018 14:08:23 +0000 (15:08 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Mar 2018 08:11:32 +0000 (09:11 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
PVE/QemuServer.pm
PVE/QemuServer/Cloudinit.pm

index 56719be48785b2f06694c7d2d1f81acb391ad84c..6237cbc0adaa4b4e5e0bbc46ec2a6c72618ca6af 100644 (file)
@@ -546,6 +546,17 @@ my $confdesc_cloudinit = {
        description => 'Specifies the cloud-init configuration format.',
        enum => ['configdrive2', 'nocloud'],
     },
+    ciuser => {
+       optional => 1,
+       type => 'string',
+       description => "cloud-init: User name to change ssh keys and password for instead of the image's configured default user.",
+    },
+    cipassword => {
+       optional => 1,
+       type => 'string',
+       description => 'cloud-init: Password to assign the user. Using this is generally not recommended. Use ssh keys instead. '
+                    . 'Also note that older cloud-init versions do not support hashed passwords.',
+    },
     searchdomain => {
        optional => 1,
        type => 'string',
index e64dfa5a8024f512d37013f68122ba7b1a84b33e..9fcb817be3df6d3ce62074d79f3f1851160d3be0 100644 (file)
@@ -61,16 +61,15 @@ sub cloudinit_userdata {
 
     my $fqdn = get_fqdn($conf);
 
-    my $content = <<"EOF";
-#cloud-config
-manage_resolv_conf: true
-EOF
+    my $content = "#cloud-config\n";
+    $content .= "manage_resolv_conf: true\n";
 
-    my $username = 'blub';
-    my $encpw = PVE::Tools::encrypt_pw('foo');
+    my $username = $conf->{ciuser};
+    my $password = $conf->{cipassword};
 
     $content .= "user: $username\n" if defined($username);
-    $content .= "password: $encpw\n" if defined($encpw);
+    $content .= "disable_root: False\n" if defined($username) && $username eq 'root';
+    $content .= "password: $password\n" if defined($password);
 
     if (defined(my $keys = $conf->{sshkeys})) {
        $keys = URI::Escape::uri_unescape($keys);
@@ -84,9 +83,10 @@ EOF
     $content .= "chpasswd:\n";
     $content .= "  expire: False\n";
 
-    # FIXME: we probably need an option to disable this?
-    $content .= "users:\n";
-    $content .= "  - default\n";
+    if (!defined($username) || $username ne 'root') {
+       $content .= "users:\n";
+       $content .= "  - default\n";
+    }
 
     $content .= "package_upgrade: true\n";