Support check and diff mode for merge_config and merge_yaml module
Change-Id: Ib2ca736e08f48da88bb74feb5cd1efce3b860ab7 Partially-Implements: blueprint ansible-check-mode
This commit is contained in:
parent
b60468f06e
commit
1db352f007
@ -19,7 +19,10 @@
|
|||||||
import collections
|
import collections
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from ansible import constants
|
||||||
from ansible.plugins import action
|
from ansible.plugins import action
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
|
|
||||||
@ -131,22 +134,34 @@ class ActionModule(action.ActionBase):
|
|||||||
|
|
||||||
fakefile = StringIO()
|
fakefile = StringIO()
|
||||||
config.write(fakefile)
|
config.write(fakefile)
|
||||||
|
full_source = fakefile.getvalue()
|
||||||
remote_path = self._connection._shell.join_path(tmp, 'src')
|
|
||||||
xfered = self._transfer_data(remote_path, fakefile.getvalue())
|
|
||||||
fakefile.close()
|
fakefile.close()
|
||||||
|
|
||||||
new_module_args = self._task.args.copy()
|
local_tempdir = tempfile.mkdtemp(dir=constants.DEFAULT_LOCAL_TMP)
|
||||||
new_module_args.pop('sources', None)
|
|
||||||
|
|
||||||
new_module_args.update(
|
try:
|
||||||
dict(
|
result_file = os.path.join(local_tempdir, 'source')
|
||||||
src=xfered
|
with open(result_file, 'wb') as f:
|
||||||
|
f.write(full_source)
|
||||||
|
|
||||||
|
new_task = self._task.copy()
|
||||||
|
new_task.args.pop('sources', None)
|
||||||
|
|
||||||
|
new_task.args.update(
|
||||||
|
dict(
|
||||||
|
src=result_file
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
result.update(self._execute_module(module_name='copy',
|
copy_action = self._shared_loader_obj.action_loader.get(
|
||||||
module_args=new_module_args,
|
'copy',
|
||||||
task_vars=task_vars,
|
task=new_task,
|
||||||
tmp=tmp))
|
connection=self._connection,
|
||||||
|
play_context=self._play_context,
|
||||||
|
loader=self._loader,
|
||||||
|
templar=self._templar,
|
||||||
|
shared_loader_obj=self._shared_loader_obj)
|
||||||
|
result.update(copy_action.run(task_vars=task_vars))
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(local_tempdir)
|
||||||
return result
|
return result
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
from yaml import safe_load
|
from yaml import safe_load
|
||||||
@ -28,6 +30,7 @@ except ImportError:
|
|||||||
from yaml import Loader # noqa: F401
|
from yaml import Loader # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
|
from ansible import constants
|
||||||
from ansible.plugins import action
|
from ansible.plugins import action
|
||||||
|
|
||||||
|
|
||||||
@ -78,19 +81,31 @@ class ActionModule(action.ActionBase):
|
|||||||
# restore original vars
|
# restore original vars
|
||||||
self._templar.set_available_variables(old_vars)
|
self._templar.set_available_variables(old_vars)
|
||||||
|
|
||||||
remote_path = self._connection._shell.join_path(tmp, 'src')
|
local_tempdir = tempfile.mkdtemp(dir=constants.DEFAULT_LOCAL_TMP)
|
||||||
xfered = self._transfer_data(remote_path,
|
|
||||||
dump(output,
|
try:
|
||||||
default_flow_style=False))
|
result_file = os.path.join(local_tempdir, 'source')
|
||||||
new_module_args = self._task.args.copy()
|
with open(result_file, 'wb') as f:
|
||||||
new_module_args.update(
|
f.write(dump(output, default_flow_style=False))
|
||||||
dict(
|
|
||||||
src=xfered
|
new_task = self._task.copy()
|
||||||
|
new_task.args.pop('sources', None)
|
||||||
|
|
||||||
|
new_task.args.update(
|
||||||
|
dict(
|
||||||
|
src=result_file
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
del new_module_args['sources']
|
copy_action = self._shared_loader_obj.action_loader.get(
|
||||||
result.update(self._execute_module(module_name='copy',
|
'copy',
|
||||||
module_args=new_module_args,
|
task=new_task,
|
||||||
task_vars=task_vars,
|
connection=self._connection,
|
||||||
tmp=tmp))
|
play_context=self._play_context,
|
||||||
|
loader=self._loader,
|
||||||
|
templar=self._templar,
|
||||||
|
shared_loader_obj=self._shared_loader_obj)
|
||||||
|
result.update(copy_action.run(task_vars=task_vars))
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(local_tempdir)
|
||||||
return result
|
return result
|
||||||
|
@ -240,6 +240,7 @@
|
|||||||
owner: "{{ config_owner_user }}"
|
owner: "{{ config_owner_user }}"
|
||||||
group: "{{ config_owner_group }}"
|
group: "{{ config_owner_group }}"
|
||||||
mode: "0770"
|
mode: "0770"
|
||||||
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
when:
|
when:
|
||||||
- item.value.enabled | bool
|
- item.value.enabled | bool
|
||||||
- item.key != "kolla-toolbox"
|
- item.key != "kolla-toolbox"
|
||||||
|
@ -188,6 +188,7 @@
|
|||||||
- name: Save the returned from cron jobs for building the crontab
|
- name: Save the returned from cron jobs for building the crontab
|
||||||
set_fact:
|
set_fact:
|
||||||
cron_jobs: "{{ (cron_jobs_json.stdout | from_json).cron_jobs }}"
|
cron_jobs: "{{ (cron_jobs_json.stdout | from_json).cron_jobs }}"
|
||||||
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
when: keystone_token_provider == 'fernet'
|
when: keystone_token_provider == 'fernet'
|
||||||
|
|
||||||
- name: Copying files for keystone-fernet
|
- name: Copying files for keystone-fernet
|
||||||
@ -199,6 +200,7 @@
|
|||||||
mode: "0660"
|
mode: "0660"
|
||||||
become: true
|
become: true
|
||||||
register: keystone_fernet_confs
|
register: keystone_fernet_confs
|
||||||
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
with_items:
|
with_items:
|
||||||
- { src: "crontab.j2", dest: "crontab" }
|
- { src: "crontab.j2", dest: "crontab" }
|
||||||
- { src: "fernet-rotate.sh.j2", dest: "fernet-rotate.sh" }
|
- { src: "fernet-rotate.sh.j2", dest: "fernet-rotate.sh" }
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Support ansible check and diff module for generate configrations. You could
|
||||||
|
use ``EXTRA_OPTS='--check --diff' kolla-ansible genconfig`` to check what
|
||||||
|
the configration file will be like in dry-run mode.
|
Loading…
Reference in New Issue
Block a user