library: move `fatal()` into ca_common.py

this function is defined in various modules, let's move it to
`ca_common.py`

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
guits-multisite3
Guillaume Abrioux 2021-01-17 20:17:30 +01:00
parent e66f12d138
commit 4253de42a4
4 changed files with 18 additions and 36 deletions

View File

@ -8,6 +8,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import fatal
except ImportError:
from module_utils.ca_common import fatal
import datetime import datetime
ANSIBLE_METADATA = { ANSIBLE_METADATA = {
@ -62,16 +66,6 @@ EXAMPLES = '''
RETURN = '''# ''' RETURN = '''# '''
def fatal(message, module):
'''
Report a fatal error and exit
'''
if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))
def generate_cmd(cluster, subcommand, bucket, bucket_type, containerized=None): def generate_cmd(cluster, subcommand, bucket, bucket_type, containerized=None):
''' '''
Generate command line to execute Generate command line to execute

View File

@ -19,9 +19,9 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import is_containerized, container_exec from ansible.module_utils.ca_common import is_containerized, container_exec, fatal
except ImportError: except ImportError:
from module_utils.ca_common import is_containerized, container_exec from module_utils.ca_common import is_containerized, container_exec, fatal
import datetime import datetime
import json import json
import os import os
@ -219,17 +219,6 @@ def str_to_bool(val):
raise ValueError("Invalid input value: %s" % val) raise ValueError("Invalid input value: %s" % val)
def fatal(message, module):
'''
Report a fatal error and exit
'''
if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))
def generate_secret(): def generate_secret():
''' '''
Generate a CephX secret Generate a CephX secret

View File

@ -2,9 +2,9 @@
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import exec_command, is_containerized from ansible.module_utils.ca_common import exec_command, is_containerized, fatal
except ImportError: except ImportError:
from module_utils.ca_common import exec_command, is_containerized from module_utils.ca_common import exec_command, is_containerized, fatal
import datetime import datetime
import copy import copy
import json import json
@ -186,17 +186,6 @@ EXAMPLES = '''
''' '''
def fatal(message, module):
'''
Report a fatal error and exit
'''
if module:
module.fail_json(msg=message, changed=False, rc=1)
else:
raise(Exception(message))
def container_exec(binary, container_image): def container_exec(binary, container_image):
''' '''
Build the docker CLI to run a command inside a container Build the docker CLI to run a command inside a container

View File

@ -96,3 +96,13 @@ def exit_module(module, out, rc, cmd, err, startd, changed=False):
changed=changed, changed=changed,
) )
module.exit_json(**result) module.exit_json(**result)
def fatal(message, module):
'''
Report a fatal error and exit
'''
if module:
module.fail_json(msg=message, rc=1)
else:
raise(Exception(message))