Esempio n. 1
0
  def run(self, terms, variables, **kwargs):
    env_data = kwargs.get('env_data')
    validate = kwargs.get('validate')

    ret = []
    error_msgs = []

    for term in terms:
      services = term

      run_info = dict(
          plugin=self,
          ansible_vars=variables,
          env_data=env_data,
          validate=validate if (validate is not None) else True,
      )

      result_info = prepare_services(services, run_info=run_info)

      result_aux = result_info.get('result')
      error_msgs_aux = result_info.get('error_msgs') or list()

      if error_msgs_aux:
        error_msgs += error_msgs_aux
      else:
        ret.append(result_aux)

    if error_msgs:
      raise AnsibleError(to_text(error_text(error_msgs, 'services')))

    return ret
Esempio n. 2
0
    def params_mixer(self, params_args):
        info = mix(params_args)

        result = info.get('result')
        error_msgs = info.get('error_msgs')

        if error_msgs:
            raise AnsibleError(to_text(error_text(error_msgs, 'params_mixer')))

        return result
Esempio n. 3
0
    def run(self, terms, variables, **kwargs):
        env_data = kwargs.get('env_data')
        env = kwargs.get('env') or env_data.get('env')
        input_params = kwargs.get('input')
        custom_dir = kwargs.get('custom_dir')
        validate = kwargs.get('validate')
        context = kwargs.get('context')

        ret = []
        error_msgs = []

        for term in terms:
            content = term

            run_info = dict(
                plugin=self,
                ansible_vars=variables,
                env_data=env_data,
                validate=validate if (validate is not None) else True,
            )

            result_info = prepare_content(
                content,
                env=env,
                run_info=run_info,
                additional_info=dict(
                    input_params=input_params,
                    custom_dir=custom_dir,
                ),
            )

            result_aux = result_info.get('result')
            error_msgs_aux = result_info.get('error_msgs')

            if error_msgs_aux:
                error_msgs += error_msgs_aux
            else:
                ret.append(result_aux)

        if error_msgs:
            raise AnsibleError(
                to_text(error_text(error_msgs, context or 'content')))

        return ret
Esempio n. 4
0
def main():
  module = AnsibleModule(
      argument_spec=dict(
          identifier=dict(type='str', required=True),
          raw_data=dict(type='raw', required=True),
      )
  )

  identifier = module.params['identifier']
  raw_data = module.params['raw_data']

  info = None
  result = None
  error_msgs = list()

  if not identifier:
    error_msgs += [['msg: identifier not defined']]
  elif identifier == 's3':
    info = s3_prepare_data(raw_data)
  elif identifier == 'godaddy_nameserver':
    info = godaddy_nameserver_prepare_data(raw_data)
  elif identifier == 'godaddy_dns':
    info = godaddy_dns_prepare_data(raw_data)
  elif identifier == 'cloudflare_dns':
    info = cloudflare_dns_prepare_data(raw_data)
  elif identifier == 'fastly_cdn':
    info = fastly_cdn_prepare_data(raw_data)
  elif identifier == 'stackpath_cdn':
    info = stackpath_cdn_prepare_data(raw_data)
  else:
    error_msgs += [['msg: invalid identifier']]

  if info:
    result = info.get('result')
    error_msgs += (info.get('error_msgs') or list())

  if error_msgs:
    context = 'vars module (identifier: ' + str(identifier or '') + ')'
    module.fail_json(msg=to_text(error_text(error_msgs, context)))

  module.exit_json(changed=False, data=result)
Esempio n. 5
0
def main():
    module = AnsibleModule(argument_spec=dict(
        schema_file=dict(type='str', required=True),
        value=dict(type='raw', required=True),
        full_validation=dict(type='bool', default=True),
    ))

    schema_file = module.params['schema_file']
    value = module.params['value']
    full_validation = module.boolean(module.params['full_validation'])

    error_msgs = list()

    if os.path.exists(schema_file):
        schema = None

        try:
            schema = load_yaml_file(schema_file)
        except Exception as error:
            error_msgs += [[
                str('file: ' + schema_file),
                'msg: error when trying to load the schema file',
                'error type: ' + str(type(error)),
                'error details: ',
                traceback.format_exc().split('\n'),
            ]]

        if schema:
            error_msgs_aux = validate_schema(schema, value, full_validation)

            for value in (error_msgs_aux or []):
                new_value = [str('schema file: ' + schema_file)] + value
                error_msgs += [new_value]
    else:
        error_msgs += [[str('schema file not found: ' + schema_file)]]

    if error_msgs:
        context = "schema validation"
        module.fail_json(msg=to_text(error_text(error_msgs, context)))

    module.exit_json(changed=False)
Esempio n. 6
0
def main():
    module = AnsibleModule(argument_spec=dict(
        identifier=dict(type='str', required=True),
        data=dict(type='raw', required=True),
    ))

    identifier = module.params['identifier']
    data = module.params['data']

    info = None
    result_data = None
    changed = False
    error_msgs = list()

    if not identifier:
        error_msgs += [['msg: identifier not defined']]
    elif identifier == 'godaddy_nameserver':
        info = godaddy_manage_nameserver(prepared_item=data)
    elif identifier == 'godaddy_dns':
        info = godaddy_manage_dns(prepared_item=data)
    elif identifier == 'stackpath_cdn':
        info = stackpath_manage_cdn(prepared_item=data)
    elif identifier == 'linode_stackscript':
        info = linode_manage_stackscript(data=data)
    else:
        error_msgs += [['msg: invalid identifier']]

    if info:
        result = info.get('result')
        error_msgs += (info.get('error_msgs') or list())

    if error_msgs:
        context = 'actions module (identifier: ' + str(identifier or '') + ')'
        module.fail_json(msg=to_text(error_text(error_msgs, context)))

    changed = result.get('changed')
    result_data = result.get('data')

    module.exit_json(changed=changed, data=result_data)
Esempio n. 7
0
    def run(self, terms, variables, **kwargs):
        env_data = kwargs.get('env_data')
        input_params = kwargs.get('input_params')
        validate = kwargs.get('validate')

        ret = []
        error_msgs = []

        for term in terms:
            pod_info = dict(
                pod=term,
                input_params=input_params,
            )

            run_info = dict(
                plugin=self,
                ansible_vars=variables,
                env_data=env_data,
                validate=validate if (validate is not None) else True,
            )

            result_info = load_vars(
                pod_info=pod_info,
                run_info=run_info,
            )

            result_aux = result_info.get('result')
            error_msgs_aux = result_info.get('error_msgs') or list()

            if error_msgs_aux:
                error_msgs += error_msgs_aux
            else:
                ret.append(result_aux)

        if error_msgs:
            raise AnsibleError(to_text(error_text(error_msgs, 'pod_vars')))

        return ret
Esempio n. 8
0
    def node_dict_dependencies(
        self,
        node_dict_dependencies,
        hosts_data,
        instance_type,
        instance_index,
        ignore_unknown_nodes=None,
    ):
        info = prepare_host_dependencies(
            node_dict_dependencies=node_dict_dependencies,
            hosts_data=hosts_data,
            instance_type=instance_type,
            instance_index=instance_index,
            ignore_unknown_nodes=ignore_unknown_nodes,
        )

        result = info.get('result')
        error_msgs = info.get('error_msgs')

        if error_msgs:
            raise AnsibleError(to_text(error_text(error_msgs, 'params_mixer')))

        return result