mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
cloudinit: Fix setting root password in user-data
This commit is contained in:
@@ -1632,7 +1632,9 @@ class ParserCloudInit(VirtCLIParser):
|
||||
def parse_cloud_init(optstr):
|
||||
ret = CloudInitData()
|
||||
if optstr == 1:
|
||||
# This means bare --cloud-init, so there's nothing to parse
|
||||
# This means bare --cloud-init, so there's nothing to parse.
|
||||
log.warning("Defaulting to --cloud-init root-password=generate")
|
||||
ret.root_password = "generate"
|
||||
return ret
|
||||
|
||||
parser = ParserCloudInit(optstr)
|
||||
|
||||
@@ -29,19 +29,26 @@ def create_metadata(scratchdir, hostname=None):
|
||||
|
||||
|
||||
def create_userdata(scratchdir, cloudinit_data, username=None, password=None):
|
||||
if not password:
|
||||
password = ""
|
||||
for dummy in range(16):
|
||||
password += random.choice(string.ascii_letters + string.digits)
|
||||
content = "#cloud-config\n"
|
||||
if username:
|
||||
content += "name: %s\n" % username
|
||||
if cloudinit_data.root_password == "generate":
|
||||
pass
|
||||
else:
|
||||
if password:
|
||||
content += "password: %s\n" % password
|
||||
log.debug("Generated password for first boot: \n%s", password)
|
||||
|
||||
rootpass = cloudinit_data.root_password
|
||||
if rootpass == "generate":
|
||||
rootpass = ""
|
||||
for dummy in range(16):
|
||||
rootpass += random.choice(string.ascii_letters + string.digits)
|
||||
log.warning("Generated password for first boot: %s", rootpass)
|
||||
time.sleep(20)
|
||||
|
||||
if rootpass:
|
||||
content += "chpasswd:\n"
|
||||
content += " list: |\n"
|
||||
content += " root:%s\n" % rootpass
|
||||
content += " expire: True\n"
|
||||
|
||||
content += "runcmd:\n"
|
||||
content += "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]\n"
|
||||
log.debug("Generated cloud-init userdata:\n%s", content)
|
||||
|
||||
Reference in New Issue
Block a user