'common code for quickly building an ansible module in Python
(although you can write modules in anything that can return JSON)
see library/* for examples'

def __init__(self, argument_spec, bypass_checks=False, no_log=False, check_invalid_arguments=True, mutually_exclusive=None, required_together=None, required_one_of=None, add_file_common_args=False, supports_check_mode=False, required_if=None):

    self._name = os.path.basename(__file__)
    self.argument_spec = argument_spec
    self.supports_check_mode = supports_check_mode
    self.check_mode = False
    self.bypass_checks = bypass_checks
    self.no_log = no_log
    self.check_invalid_arguments = check_invalid_arguments
    self.mutually_exclusive = mutually_exclusive
    self.required_together = required_together
    self.required_one_of = required_one_of
    self.required_if = required_if
    self.cleanup_files = []
    self._debug = False
    self._diff = False
    self._socket_path = None
    self._verbosity = 0
    self.run_command_environ_update = {}
    self._warnings = []
    self._deprecations = []
    self.aliases = {}
    self._legal_inputs = ['_ansible_check_mode', '_ansible_no_log', '_ansible_debug', '_ansible_diff', '_ansible_verbosity', '_ansible_selinux_special_fs', '_ansible_module_name', '_ansible_version', '_ansible_syslog_facility', '_ansible_socket']
    self._options_context = list()
    if add_file_common_args:
        for (k, v) in FILE_COMMON_ARGUMENTS.items():
            if (k not in self.argument_spec):
                self.argument_spec[k] = v
    self._load_params()
    self._set_fallbacks()
    try:
        self.aliases = self._handle_aliases()
    except Exception:
        e = get_exception()
        print ('\n{"failed":    true,    "msg":    "Module    alias    error:    %s"}' % str(e))
        sys.exit(1)
    self.no_log_values = set()
    self._handle_no_log_values()
    self._check_locale()
    self._check_arguments(check_invalid_arguments)
    if (not bypass_checks):
        self._check_mutually_exclusive(mutually_exclusive)
    self._set_defaults(pre=True)
    self._CHECK_ARGUMENT_TYPES_DISPATCHER = {'str': self._check_type_str, 'list': self._check_type_list, 'dict': self._check_type_dict, 'bool': self._check_type_bool, 'int': self._check_type_int, 'float': self._check_type_float, 'path': self._check_type_path, 'raw': self._check_type_raw, 'jsonarg': self._check_type_jsonarg, 'json': self._check_type_jsonarg, 'bytes': self._check_type_bytes, 'bits': self._check_type_bits}
    if (not bypass_checks):
        self._check_required_arguments()
        self._check_argument_types()
        self._check_argument_values()
        self._check_required_together(required_together)
        self._check_required_one_of(required_one_of)
        self._check_required_if(required_if)
    self._set_defaults(pre=False)
    self._handle_options()
    if (not self.no_log):
        self._log_invocation()
    self._set_cwd()
