mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Pass arguments as list, and also more sanely touch /etc/machine-info
This commit is contained in:
parent
9b71ff7ba4
commit
c17a8cb239
@ -496,7 +496,10 @@ def get_computer_desc():
|
||||
desc = None
|
||||
hostname_cmd = salt.utils.which('hostnamectl')
|
||||
if hostname_cmd:
|
||||
desc = __salt__['cmd.run']('{0} status --pretty'.format(hostname_cmd))
|
||||
desc = __salt__['cmd.run'](
|
||||
[hostname_cmd, 'status', '--pretty'],
|
||||
python_shell=False
|
||||
)
|
||||
else:
|
||||
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
|
||||
try:
|
||||
@ -537,12 +540,15 @@ def set_computer_desc(desc):
|
||||
desc = desc.encode('string_escape').replace('"', '\\"')
|
||||
hostname_cmd = salt.utils.which('hostnamectl')
|
||||
if hostname_cmd:
|
||||
result = __salt__['cmd.retcode']('{0} set-hostname --pretty "{1}"'.format(hostname_cmd, desc))
|
||||
result = __salt__['cmd.retcode'](
|
||||
[hostname_cmd, 'set-hostname', '--pretty', desc],
|
||||
python_shell=False
|
||||
)
|
||||
return True if result == 0 else False
|
||||
|
||||
if not os.path.isfile('/etc/machine-info'):
|
||||
f = salt.utils.fopen('/etc/machine-info', 'a')
|
||||
f.close()
|
||||
with salt.utils.fopen('/etc/machine-info', 'w'):
|
||||
pass
|
||||
|
||||
is_pretty_hostname_found = False
|
||||
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
|
||||
|
Loading…
Reference in New Issue
Block a user