mirror of https://github.com/ceph/ceph-ansible.git
Merge pull request #1082 from albertomurillo/v2.2
sync config_template plugin with master branchpull/1068/head
commit
200388d532
|
@ -267,7 +267,7 @@ class ActionModule(object):
|
||||||
else:
|
else:
|
||||||
config.set(str(section), str(key), str(value))
|
config.set(str(section), str(key), str(value))
|
||||||
|
|
||||||
def return_config_overrides_ini(self, config_overrides, resultant):
|
def return_config_overrides_ini(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Returns string value from a modified config file.
|
"""Returns string value from a modified config file.
|
||||||
|
|
||||||
:param config_overrides: ``dict``
|
:param config_overrides: ``dict``
|
||||||
|
@ -278,6 +278,7 @@ class ActionModule(object):
|
||||||
dict_type=MultiKeyDict,
|
dict_type=MultiKeyDict,
|
||||||
allow_no_value=True
|
allow_no_value=True
|
||||||
)
|
)
|
||||||
|
config.optionxform = str
|
||||||
config_object = io.BytesIO(resultant.encode('utf-8'))
|
config_object = io.BytesIO(resultant.encode('utf-8'))
|
||||||
config.readfp(config_object)
|
config.readfp(config_object)
|
||||||
for section, items in config_overrides.items():
|
for section, items in config_overrides.items():
|
||||||
|
@ -307,7 +308,7 @@ class ActionModule(object):
|
||||||
finally:
|
finally:
|
||||||
resultant_bytesio.close()
|
resultant_bytesio.close()
|
||||||
|
|
||||||
def return_config_overrides_json(self, config_overrides, resultant):
|
def return_config_overrides_json(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Returns config json
|
"""Returns config json
|
||||||
|
|
||||||
Its important to note that file ordering will not be preserved as the
|
Its important to note that file ordering will not be preserved as the
|
||||||
|
@ -320,7 +321,8 @@ class ActionModule(object):
|
||||||
original_resultant = json.loads(resultant)
|
original_resultant = json.loads(resultant)
|
||||||
merged_resultant = self._merge_dict(
|
merged_resultant = self._merge_dict(
|
||||||
base_items=original_resultant,
|
base_items=original_resultant,
|
||||||
new_items=config_overrides
|
new_items=config_overrides,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
return json.dumps(
|
return json.dumps(
|
||||||
merged_resultant,
|
merged_resultant,
|
||||||
|
@ -328,7 +330,7 @@ class ActionModule(object):
|
||||||
sort_keys=True
|
sort_keys=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def return_config_overrides_yaml(self, config_overrides, resultant):
|
def return_config_overrides_yaml(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Return config yaml.
|
"""Return config yaml.
|
||||||
|
|
||||||
:param config_overrides: ``dict``
|
:param config_overrides: ``dict``
|
||||||
|
@ -338,7 +340,8 @@ class ActionModule(object):
|
||||||
original_resultant = yaml.safe_load(resultant)
|
original_resultant = yaml.safe_load(resultant)
|
||||||
merged_resultant = self._merge_dict(
|
merged_resultant = self._merge_dict(
|
||||||
base_items=original_resultant,
|
base_items=original_resultant,
|
||||||
new_items=config_overrides
|
new_items=config_overrides,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
return yaml.safe_dump(
|
return yaml.safe_dump(
|
||||||
merged_resultant,
|
merged_resultant,
|
||||||
|
@ -346,7 +349,7 @@ class ActionModule(object):
|
||||||
width=1000,
|
width=1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _merge_dict(self, base_items, new_items):
|
def _merge_dict(self, base_items, new_items, list_extend=True):
|
||||||
"""Recursively merge new_items into base_items.
|
"""Recursively merge new_items into base_items.
|
||||||
|
|
||||||
:param base_items: ``dict``
|
:param base_items: ``dict``
|
||||||
|
@ -363,6 +366,9 @@ class ActionModule(object):
|
||||||
base_items[key] = re.split(', |,|\n', value)
|
base_items[key] = re.split(', |,|\n', value)
|
||||||
base_items[key] = [i.strip() for i in base_items[key] if i]
|
base_items[key] = [i.strip() for i in base_items[key] if i]
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
|
if isinstance(base_items.get(key), list) and list_extend:
|
||||||
|
base_items[key].extend(value)
|
||||||
|
else:
|
||||||
base_items[key] = value
|
base_items[key] = value
|
||||||
else:
|
else:
|
||||||
base_items[key] = new_items[key]
|
base_items[key] = new_items[key]
|
||||||
|
@ -417,7 +423,8 @@ class ActionModule(object):
|
||||||
type_merger = getattr(self, CONFIG_TYPES.get(config_type))
|
type_merger = getattr(self, CONFIG_TYPES.get(config_type))
|
||||||
resultant = type_merger(
|
resultant = type_merger(
|
||||||
config_overrides=config_overrides,
|
config_overrides=config_overrides,
|
||||||
resultant=resultant
|
resultant=resultant,
|
||||||
|
list_extend=options.get('list_extend', True)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Retemplate the resultant object as it may have new data within it
|
# Retemplate the resultant object as it may have new data within it
|
||||||
|
@ -445,6 +452,7 @@ class ActionModule(object):
|
||||||
# Remove data types that are not available to the copy module
|
# Remove data types that are not available to the copy module
|
||||||
complex_args.pop('config_overrides')
|
complex_args.pop('config_overrides')
|
||||||
complex_args.pop('config_type')
|
complex_args.pop('config_type')
|
||||||
|
complex_args.pop('list_extend', None)
|
||||||
|
|
||||||
# Return the copy module status. Access to protected method is
|
# Return the copy module status. Access to protected method is
|
||||||
# unavoidable in Ansible 1.x.
|
# unavoidable in Ansible 1.x.
|
||||||
|
|
|
@ -465,7 +465,12 @@ class ActionModule(ActionBase):
|
||||||
"""Run the method"""
|
"""Run the method"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remote_user = task_vars.get('ansible_ssh_user') or self._play_context.remote_user
|
remote_user = task_vars.get('ansible_user')
|
||||||
|
if not remote_user:
|
||||||
|
remote_user = task_vars.get('ansible_ssh_user')
|
||||||
|
if not remote_user:
|
||||||
|
remote_user = self._play_context.remote_user
|
||||||
|
|
||||||
if not tmp:
|
if not tmp:
|
||||||
tmp = self._make_tmp_path(remote_user)
|
tmp = self._make_tmp_path(remote_user)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -267,7 +267,7 @@ class ActionModule(object):
|
||||||
else:
|
else:
|
||||||
config.set(str(section), str(key), str(value))
|
config.set(str(section), str(key), str(value))
|
||||||
|
|
||||||
def return_config_overrides_ini(self, config_overrides, resultant):
|
def return_config_overrides_ini(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Returns string value from a modified config file.
|
"""Returns string value from a modified config file.
|
||||||
|
|
||||||
:param config_overrides: ``dict``
|
:param config_overrides: ``dict``
|
||||||
|
@ -278,6 +278,7 @@ class ActionModule(object):
|
||||||
dict_type=MultiKeyDict,
|
dict_type=MultiKeyDict,
|
||||||
allow_no_value=True
|
allow_no_value=True
|
||||||
)
|
)
|
||||||
|
config.optionxform = str
|
||||||
config_object = io.BytesIO(resultant.encode('utf-8'))
|
config_object = io.BytesIO(resultant.encode('utf-8'))
|
||||||
config.readfp(config_object)
|
config.readfp(config_object)
|
||||||
for section, items in config_overrides.items():
|
for section, items in config_overrides.items():
|
||||||
|
@ -307,7 +308,7 @@ class ActionModule(object):
|
||||||
finally:
|
finally:
|
||||||
resultant_bytesio.close()
|
resultant_bytesio.close()
|
||||||
|
|
||||||
def return_config_overrides_json(self, config_overrides, resultant):
|
def return_config_overrides_json(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Returns config json
|
"""Returns config json
|
||||||
|
|
||||||
Its important to note that file ordering will not be preserved as the
|
Its important to note that file ordering will not be preserved as the
|
||||||
|
@ -320,7 +321,8 @@ class ActionModule(object):
|
||||||
original_resultant = json.loads(resultant)
|
original_resultant = json.loads(resultant)
|
||||||
merged_resultant = self._merge_dict(
|
merged_resultant = self._merge_dict(
|
||||||
base_items=original_resultant,
|
base_items=original_resultant,
|
||||||
new_items=config_overrides
|
new_items=config_overrides,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
return json.dumps(
|
return json.dumps(
|
||||||
merged_resultant,
|
merged_resultant,
|
||||||
|
@ -328,7 +330,7 @@ class ActionModule(object):
|
||||||
sort_keys=True
|
sort_keys=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def return_config_overrides_yaml(self, config_overrides, resultant):
|
def return_config_overrides_yaml(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Return config yaml.
|
"""Return config yaml.
|
||||||
|
|
||||||
:param config_overrides: ``dict``
|
:param config_overrides: ``dict``
|
||||||
|
@ -338,7 +340,8 @@ class ActionModule(object):
|
||||||
original_resultant = yaml.safe_load(resultant)
|
original_resultant = yaml.safe_load(resultant)
|
||||||
merged_resultant = self._merge_dict(
|
merged_resultant = self._merge_dict(
|
||||||
base_items=original_resultant,
|
base_items=original_resultant,
|
||||||
new_items=config_overrides
|
new_items=config_overrides,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
return yaml.safe_dump(
|
return yaml.safe_dump(
|
||||||
merged_resultant,
|
merged_resultant,
|
||||||
|
@ -346,7 +349,7 @@ class ActionModule(object):
|
||||||
width=1000,
|
width=1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _merge_dict(self, base_items, new_items):
|
def _merge_dict(self, base_items, new_items, list_extend=True):
|
||||||
"""Recursively merge new_items into base_items.
|
"""Recursively merge new_items into base_items.
|
||||||
|
|
||||||
:param base_items: ``dict``
|
:param base_items: ``dict``
|
||||||
|
@ -363,6 +366,9 @@ class ActionModule(object):
|
||||||
base_items[key] = re.split(', |,|\n', value)
|
base_items[key] = re.split(', |,|\n', value)
|
||||||
base_items[key] = [i.strip() for i in base_items[key] if i]
|
base_items[key] = [i.strip() for i in base_items[key] if i]
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
|
if isinstance(base_items.get(key), list) and list_extend:
|
||||||
|
base_items[key].extend(value)
|
||||||
|
else:
|
||||||
base_items[key] = value
|
base_items[key] = value
|
||||||
else:
|
else:
|
||||||
base_items[key] = new_items[key]
|
base_items[key] = new_items[key]
|
||||||
|
@ -417,7 +423,8 @@ class ActionModule(object):
|
||||||
type_merger = getattr(self, CONFIG_TYPES.get(config_type))
|
type_merger = getattr(self, CONFIG_TYPES.get(config_type))
|
||||||
resultant = type_merger(
|
resultant = type_merger(
|
||||||
config_overrides=config_overrides,
|
config_overrides=config_overrides,
|
||||||
resultant=resultant
|
resultant=resultant,
|
||||||
|
list_extend=options.get('list_extend', True)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Retemplate the resultant object as it may have new data within it
|
# Retemplate the resultant object as it may have new data within it
|
||||||
|
@ -445,6 +452,7 @@ class ActionModule(object):
|
||||||
# Remove data types that are not available to the copy module
|
# Remove data types that are not available to the copy module
|
||||||
complex_args.pop('config_overrides')
|
complex_args.pop('config_overrides')
|
||||||
complex_args.pop('config_type')
|
complex_args.pop('config_type')
|
||||||
|
complex_args.pop('list_extend', None)
|
||||||
|
|
||||||
# Return the copy module status. Access to protected method is
|
# Return the copy module status. Access to protected method is
|
||||||
# unavoidable in Ansible 1.x.
|
# unavoidable in Ansible 1.x.
|
||||||
|
|
|
@ -262,7 +262,7 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
|
||||||
class ActionModule(ActionBase):
|
class ActionModule(ActionBase):
|
||||||
TRANSFERS_FILES = True
|
TRANSFERS_FILES = True
|
||||||
|
|
||||||
def return_config_overrides_ini(self, config_overrides, resultant):
|
def return_config_overrides_ini(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Returns string value from a modified config file.
|
"""Returns string value from a modified config file.
|
||||||
|
|
||||||
:param config_overrides: ``dict``
|
:param config_overrides: ``dict``
|
||||||
|
@ -338,7 +338,7 @@ class ActionModule(ActionBase):
|
||||||
else:
|
else:
|
||||||
config.set(str(section), str(key), str(value))
|
config.set(str(section), str(key), str(value))
|
||||||
|
|
||||||
def return_config_overrides_json(self, config_overrides, resultant):
|
def return_config_overrides_json(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Returns config json
|
"""Returns config json
|
||||||
|
|
||||||
Its important to note that file ordering will not be preserved as the
|
Its important to note that file ordering will not be preserved as the
|
||||||
|
@ -351,7 +351,8 @@ class ActionModule(ActionBase):
|
||||||
original_resultant = json.loads(resultant)
|
original_resultant = json.loads(resultant)
|
||||||
merged_resultant = self._merge_dict(
|
merged_resultant = self._merge_dict(
|
||||||
base_items=original_resultant,
|
base_items=original_resultant,
|
||||||
new_items=config_overrides
|
new_items=config_overrides,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
return json.dumps(
|
return json.dumps(
|
||||||
merged_resultant,
|
merged_resultant,
|
||||||
|
@ -359,7 +360,7 @@ class ActionModule(ActionBase):
|
||||||
sort_keys=True
|
sort_keys=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def return_config_overrides_yaml(self, config_overrides, resultant):
|
def return_config_overrides_yaml(self, config_overrides, resultant, list_extend=True):
|
||||||
"""Return config yaml.
|
"""Return config yaml.
|
||||||
|
|
||||||
:param config_overrides: ``dict``
|
:param config_overrides: ``dict``
|
||||||
|
@ -369,7 +370,8 @@ class ActionModule(ActionBase):
|
||||||
original_resultant = yaml.safe_load(resultant)
|
original_resultant = yaml.safe_load(resultant)
|
||||||
merged_resultant = self._merge_dict(
|
merged_resultant = self._merge_dict(
|
||||||
base_items=original_resultant,
|
base_items=original_resultant,
|
||||||
new_items=config_overrides
|
new_items=config_overrides,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
return yaml.safe_dump(
|
return yaml.safe_dump(
|
||||||
merged_resultant,
|
merged_resultant,
|
||||||
|
@ -377,7 +379,7 @@ class ActionModule(ActionBase):
|
||||||
width=1000,
|
width=1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _merge_dict(self, base_items, new_items):
|
def _merge_dict(self, base_items, new_items, list_extend=True):
|
||||||
"""Recursively merge new_items into base_items.
|
"""Recursively merge new_items into base_items.
|
||||||
|
|
||||||
:param base_items: ``dict``
|
:param base_items: ``dict``
|
||||||
|
@ -387,14 +389,15 @@ class ActionModule(ActionBase):
|
||||||
for key, value in new_items.iteritems():
|
for key, value in new_items.iteritems():
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
base_items[key] = self._merge_dict(
|
base_items[key] = self._merge_dict(
|
||||||
base_items.get(key, {}),
|
base_items=base_items.get(key, {}),
|
||||||
value
|
new_items=value,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
elif not isinstance(value, int) and (',' in value or '\n' in value):
|
elif not isinstance(value, int) and (',' in value or '\n' in value):
|
||||||
base_items[key] = re.split(',|\n', value)
|
base_items[key] = re.split(',|\n', value)
|
||||||
base_items[key] = [i.strip() for i in base_items[key] if i]
|
base_items[key] = [i.strip() for i in base_items[key] if i]
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
if key in base_items and isinstance(base_items[key], list):
|
if isinstance(base_items.get(key), list) and list_extend:
|
||||||
base_items[key].extend(value)
|
base_items[key].extend(value)
|
||||||
else:
|
else:
|
||||||
base_items[key] = value
|
base_items[key] = value
|
||||||
|
@ -416,17 +419,6 @@ class ActionModule(ActionBase):
|
||||||
# Access to protected method is unavoidable in Ansible
|
# Access to protected method is unavoidable in Ansible
|
||||||
searchpath = [self._loader._basedir]
|
searchpath = [self._loader._basedir]
|
||||||
|
|
||||||
faf = self._task.first_available_file
|
|
||||||
if faf:
|
|
||||||
task_file = task_vars.get('_original_file', None, 'templates')
|
|
||||||
source = self._get_first_available_file(faf, task_file)
|
|
||||||
if not source:
|
|
||||||
return False, dict(
|
|
||||||
failed=True,
|
|
||||||
msg="could not find src in first_available_file list"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Access to protected method is unavoidable in Ansible
|
|
||||||
if self._task._role:
|
if self._task._role:
|
||||||
file_path = self._task._role._role_path
|
file_path = self._task._role._role_path
|
||||||
searchpath.insert(1, C.DEFAULT_ROLES_PATH)
|
searchpath.insert(1, C.DEFAULT_ROLES_PATH)
|
||||||
|
@ -448,6 +440,7 @@ class ActionModule(ActionBase):
|
||||||
searchpath.insert(1, os.path.dirname(source))
|
searchpath.insert(1, os.path.dirname(source))
|
||||||
|
|
||||||
_dest = self._task.args.get('dest')
|
_dest = self._task.args.get('dest')
|
||||||
|
list_extend = self._task.args.get('list_extend')
|
||||||
if not _dest:
|
if not _dest:
|
||||||
return False, dict(
|
return False, dict(
|
||||||
failed=True,
|
failed=True,
|
||||||
|
@ -464,14 +457,20 @@ class ActionModule(ActionBase):
|
||||||
dest=user_dest,
|
dest=user_dest,
|
||||||
config_overrides=self._task.args.get('config_overrides', dict()),
|
config_overrides=self._task.args.get('config_overrides', dict()),
|
||||||
config_type=config_type,
|
config_type=config_type,
|
||||||
searchpath=searchpath
|
searchpath=searchpath,
|
||||||
|
list_extend=list_extend
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
"""Run the method"""
|
"""Run the method"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remote_user = task_vars.get('ansible_ssh_user') or self._play_context.remote_user
|
remote_user = task_vars.get('ansible_user')
|
||||||
|
if not remote_user:
|
||||||
|
remote_user = task_vars.get('ansible_ssh_user')
|
||||||
|
if not remote_user:
|
||||||
|
remote_user = self._play_context.remote_user
|
||||||
|
|
||||||
if not tmp:
|
if not tmp:
|
||||||
tmp = self._make_tmp_path(remote_user)
|
tmp = self._make_tmp_path(remote_user)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
@ -531,7 +530,8 @@ class ActionModule(ActionBase):
|
||||||
type_merger = getattr(self, CONFIG_TYPES.get(_vars['config_type']))
|
type_merger = getattr(self, CONFIG_TYPES.get(_vars['config_type']))
|
||||||
resultant = type_merger(
|
resultant = type_merger(
|
||||||
config_overrides=_vars['config_overrides'],
|
config_overrides=_vars['config_overrides'],
|
||||||
resultant=resultant
|
resultant=resultant,
|
||||||
|
list_extend=_vars.get('list_extend', True)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Re-template the resultant object as it may have new data within it
|
# Re-template the resultant object as it may have new data within it
|
||||||
|
@ -562,6 +562,7 @@ class ActionModule(ActionBase):
|
||||||
# Remove data types that are not available to the copy module
|
# Remove data types that are not available to the copy module
|
||||||
new_module_args.pop('config_overrides', None)
|
new_module_args.pop('config_overrides', None)
|
||||||
new_module_args.pop('config_type', None)
|
new_module_args.pop('config_type', None)
|
||||||
|
new_module_args.pop('list_extend', None)
|
||||||
|
|
||||||
# Run the copy module
|
# Run the copy module
|
||||||
return self._execute_module(
|
return self._execute_module(
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
- name: get ceph version
|
- name: get ceph version
|
||||||
command: ceph --version
|
command: ceph --version
|
||||||
changed_when: false
|
changed_when: false
|
||||||
always_run: true
|
check_mode: no
|
||||||
register: ceph_version
|
register: ceph_version
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
- name: check init system
|
- name: check init system
|
||||||
slurp:
|
slurp:
|
||||||
src: /proc/1/comm
|
src: /proc/1/comm
|
||||||
always_run: true
|
check_mode: no
|
||||||
register: init_system
|
register: init_system
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
command: sysctl -b vm.min_free_kbytes
|
command: sysctl -b vm.min_free_kbytes
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
always_run: true
|
check_mode: no
|
||||||
register: default_vm_min_free_kbytes
|
register: default_vm_min_free_kbytes
|
||||||
|
|
||||||
- name: define vm.min_free_kbytes
|
- name: define vm.min_free_kbytes
|
||||||
|
|
Loading…
Reference in New Issue