35 lines
774 B
Python
Executable File
35 lines
774 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import yaml
|
|
cloudcfg = "/etc/cloud/cloud.cfg"
|
|
user = "cloud-user"
|
|
|
|
with open(cloudcfg) as f:
|
|
cfg = yaml.safe_load(f)
|
|
|
|
synver = "1"
|
|
try:
|
|
if cfg['system_info']['default_user']['name']:
|
|
synver = "2"
|
|
except KeyError:
|
|
pass
|
|
|
|
if synver == "1":
|
|
if cfg['user'] == user:
|
|
print("No change needed")
|
|
exit()
|
|
else:
|
|
cfg['user'] = user
|
|
elif synver == "2":
|
|
if cfg['system_info']['default_user']['name'] == user:
|
|
print("No change needed")
|
|
exit()
|
|
else:
|
|
# Change the user to cloud-user
|
|
cfg['system_info']['default_user']['name'] = user
|
|
cfg['system_info']['default_user']['gecos'] = "Cloud User"
|
|
print(cfg['system_info']['default_user']['name'])
|
|
|
|
with open(cloudcfg, "w") as f:
|
|
yaml.dump(cfg, f, default_flow_style=False)
|