Fix apache.config with multiple statement

At this moment when you post more than one statement in config only last
is used. Also file is rewrited multiple times until last statement is
written.
Example:
salt '*' apache.config /etc/httpd/conf.d/ports.conf config="[{'Listen': '8080'}, {'Proxy': "Something"}]"
Ends only with
   Proxy Something
and ignore Listen 8080,
This patch fix this issue.
This commit is contained in:
Viktor Krivak 2017-08-25 15:08:57 +02:00
parent 669b376abf
commit 4164047951

View file

@ -446,11 +446,15 @@ def config(name, config, edit=True):
salt '*' apache.config /etc/httpd/conf.d/ports.conf config="[{'Listen': '22'}]"
'''
configs = []
for entry in config:
key = next(six.iterkeys(entry))
configs = _parse_config(entry[key], key)
if edit:
with salt.utils.fopen(name, 'w') as configfile:
configfile.write('# This file is managed by Salt.\n')
configfile.write(configs)
return configs
configs.append(_parse_config(entry[key], key))
# Python auto-correct line endings
configstext = "\n".join(configs)
if edit:
with salt.utils.fopen(name, 'w') as configfile:
configfile.write('# This file is managed by Salt.\n')
configfile.write(configstext)
return configstext