aboutsummaryrefslogtreecommitdiff
path: root/ansible/action_plugins
diff options
context:
space:
mode:
authorPierre Riteau <pierre@stackhpc.com>2021-03-05 15:11:55 +0100
committerPierre Riteau <pierre@stackhpc.com>2021-03-05 15:12:23 +0100
commit2b723ead051b7f722ad61db1bb65a07259817719 (patch)
treecba804509572adc1d88fa1833a3ba6012398dde2 /ansible/action_plugins
parentcef8c8b3de97444f09a46d533cbc6654df9ac2e0 (diff)
downloadkolla-ansible-2b723ead051b7f722ad61db1bb65a07259817719.tar.gz
kolla-ansible-2b723ead051b7f722ad61db1bb65a07259817719.zip
Remove whitespace around equal signs in zookeeper.cfg
The merge_configs action plugin is updated with an option to control whether whitespace should be used around equal signs. The default remains to use whitespace: only zookeeper.cfg doesn't use them. This is to avoid issues with the zkCleanup.sh script which expects no whitespace. The ZooKeeper documentation also uses no whitespace in configuration file examples. Change-Id: Ia082a1c002cc4e8b04f7696fdee827b747c6d13f Closes-Bug: #1917490
Diffstat (limited to 'ansible/action_plugins')
-rw-r--r--ansible/action_plugins/merge_configs.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/ansible/action_plugins/merge_configs.py b/ansible/action_plugins/merge_configs.py
index 54463e653..d20edf1da 100644
--- a/ansible/action_plugins/merge_configs.py
+++ b/ansible/action_plugins/merge_configs.py
@@ -46,6 +46,12 @@ options:
default: None
required: True
type: str
+ whitespace:
+ description:
+ - Whether whitespace characters should be used around equal signs
+ default: True
+ required: False
+ type: bool
author: Sam Yaple
'''
@@ -67,10 +73,11 @@ Merge multiple configs:
class OverrideConfigParser(iniparser.BaseParser):
- def __init__(self):
+ def __init__(self, whitespace=True):
self._cur_sections = collections.OrderedDict()
self._sections = collections.OrderedDict()
self._cur_section = None
+ self._whitespace = ' ' if whitespace else ''
def assignment(self, key, value):
if self._cur_section is None:
@@ -107,12 +114,20 @@ class OverrideConfigParser(iniparser.BaseParser):
def write_key_value(key, values):
for v in values:
if not v:
- fp.write('{} =\n'.format(key))
+ fp.write('{key}{ws}=\n'.format(
+ key=key, ws=self._whitespace))
for index, value in enumerate(v):
if index == 0:
- fp.write('{} = {}\n'.format(key, value))
+ fp.write('{key}{ws}={ws}{value}\n'.format(
+ key=key,
+ ws=self._whitespace,
+ value=value))
else:
- fp.write('{} {}\n'.format(len(key) * ' ', value))
+ indent_size = len(key) + len(self._whitespace) * 2 + 1
+ ws_indent = ' ' * indent_size
+ fp.write('{ws_indent}{value}\n'.format(
+ ws_indent=ws_indent,
+ value=value))
def write_section(section):
for key, values in section.items():
@@ -158,7 +173,8 @@ class ActionModule(action.ActionBase):
if not isinstance(sources, list):
sources = [sources]
- config = OverrideConfigParser()
+ config = OverrideConfigParser(
+ whitespace=self._task.args.get('whitespace', True))
for source in sources:
self.read_config(source, config)
@@ -179,6 +195,7 @@ class ActionModule(action.ActionBase):
new_task = self._task.copy()
new_task.args.pop('sources', None)
+ new_task.args.pop('whitespace', None)
new_task.args.update(
dict(