Pass arguments as list, and also more sanely touch /etc/machine-info

This commit is contained in:
Erik Johnson 2017-03-17 11:33:41 -05:00
parent 9b71ff7ba4
commit c17a8cb239

View File

@ -496,7 +496,10 @@ def get_computer_desc():
desc = None desc = None
hostname_cmd = salt.utils.which('hostnamectl') hostname_cmd = salt.utils.which('hostnamectl')
if hostname_cmd: 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: else:
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$') pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
try: try:
@ -537,12 +540,15 @@ def set_computer_desc(desc):
desc = desc.encode('string_escape').replace('"', '\\"') desc = desc.encode('string_escape').replace('"', '\\"')
hostname_cmd = salt.utils.which('hostnamectl') hostname_cmd = salt.utils.which('hostnamectl')
if hostname_cmd: 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 return True if result == 0 else False
if not os.path.isfile('/etc/machine-info'): if not os.path.isfile('/etc/machine-info'):
f = salt.utils.fopen('/etc/machine-info', 'a') with salt.utils.fopen('/etc/machine-info', 'w'):
f.close() pass
is_pretty_hostname_found = False is_pretty_hostname_found = False
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$') pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')