def put_role_mapping(
        self,
        *,
        name: str,
        enabled: t.Optional[bool] = None,
        error_trace: t.Optional[bool] = None,
        filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
        human: t.Optional[bool] = None,
        metadata: t.Optional[t.Mapping[str, t.Any]] = None,
        pretty: t.Optional[bool] = None,
        refresh: t.Optional[
            t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
        ] = None,
        role_templates: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
        roles: t.Optional[t.Sequence[str]] = None,
        rules: t.Optional[t.Mapping[str, t.Any]] = None,
        run_as: t.Optional[t.Sequence[str]] = None,
        body: t.Optional[t.Dict[str, t.Any]] = None,
    ) -> ObjectApiResponse[t.Any]:
        """
        .. raw:: html

          <p>Create or update role mappings.</p>
          <p>Role mappings define which roles are assigned to each user.
          Each mapping has rules that identify users and a list of roles that are granted to those users.
          The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files. The create or update role mappings API cannot update role mappings that are defined in role mapping files.</p>
          <p>NOTE: This API does not create roles. Rather, it maps users to existing roles.
          Roles can be created by using the create or update roles API or roles files.</p>
          <p><strong>Role templates</strong></p>
          <p>The most common use for role mappings is to create a mapping from a known value on the user to a fixed role name.
          For example, all users in the <code>cn=admin,dc=example,dc=com</code> LDAP group should be given the superuser role in Elasticsearch.
          The <code>roles</code> field is used for this purpose.</p>
          <p>For more complex needs, it is possible to use Mustache templates to dynamically determine the names of the roles that should be granted to the user.
          The <code>role_templates</code> field is used for this purpose.</p>
          <p>NOTE: To use role templates successfully, the relevant scripting feature must be enabled.
          Otherwise, all attempts to create a role mapping with role templates fail.</p>
          <p>All of the user fields that are available in the role mapping rules are also available in the role templates.
          Thus it is possible to assign a user to a role that reflects their username, their groups, or the name of the realm to which they authenticated.</p>
          <p>By default a template is evaluated to produce a single string that is the name of the role which should be assigned to the user.
          If the format of the template is set to &quot;json&quot; then the template is expected to produce a JSON string or an array of JSON strings for the role names.</p>


        `<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-put-role-mapping>`_

        :param name: The distinct name that identifies the role mapping. The name is
            used solely as an identifier to facilitate interaction via the API; it does
            not affect the behavior of the mapping in any way.
        :param enabled: Mappings that have `enabled` set to `false` are ignored when
            role mapping is performed.
        :param metadata: Additional metadata that helps define which roles are assigned
            to each user. Within the metadata object, keys beginning with `_` are reserved
            for system usage.
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        :param role_templates: A list of Mustache templates that will be evaluated to
            determine the roles names that should granted to the users that match the
            role mapping rules. Exactly one of `roles` or `role_templates` must be specified.
        :param roles: A list of role names that are granted to the users that match the
            role mapping rules. Exactly one of `roles` or `role_templates` must be specified.
        :param rules: The rules that determine which users should be matched by the mapping.
            A rule is a logical condition that is expressed by using a JSON DSL.
        :param run_as:
        """
        if name in SKIP_IN_PATH:
            raise ValueError("Empty value passed for parameter 'name'")
        __path_parts: t.Dict[str, str] = {"name": _quote(name)}
        __path = f'/_security/role_mapping/{__path_parts["name"]}'
        __query: t.Dict[str, t.Any] = {}
        __body: t.Dict[str, t.Any] = body if body is not None else {}
        if error_trace is not None:
            __query["error_trace"] = error_trace
        if filter_path is not None:
            __query["filter_path"] = filter_path
        if human is not None:
            __query["human"] = human
        if pretty is not None:
            __query["pretty"] = pretty
        if refresh is not None:
            __query["refresh"] = refresh
        if not __body:
            if enabled is not None:
                __body["enabled"] = enabled
            if metadata is not None:
                __body["metadata"] = metadata
            if role_templates is not None:
                __body["role_templates"] = role_templates
            if roles is not None:
                __body["roles"] = roles
            if rules is not None:
                __body["rules"] = rules
            if run_as is not None:
                __body["run_as"] = run_as
        __headers = {"accept": "application/json", "content-type": "application/json"}
        return self.perform_request(  # type: ignore[return-value]
            "PUT",
            __path,
            params=__query,
            headers=__headers,
            body=__body,
            endpoint_id="security.put_role_mapping",
            path_parts=__path_parts,
        )

        .. raw:: html

          <p>Create or update role mappings.</p>
          <p>Role mappings define which roles are assigned to each user.
          Each mapping has rules that identify users and a list of roles that are granted to those users.
          The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files. The create or update role mappings API cannot update role mappings that are defined in role mapping files.</p>
          <p>NOTE: This API does not create roles. Rather, it maps users to existing roles.
          Roles can be created by using the create or update roles API or roles files.</p>
          <p><strong>Role templates</strong></p>
          <p>The most common use for role mappings is to create a mapping from a known value on the user to a fixed role name.
          For example, all users in the <code>cn=admin,dc=example,dc=com</code> LDAP group should be given the superuser role in Elasticsearch.
          The <code>roles</code> field is used for this purpose.</p>
          <p>For more complex needs, it is possible to use Mustache templates to dynamically determine the names of the roles that should be granted to the user.
          The <code>role_templates</code> field is used for this purpose.</p>
          <p>NOTE: To use role templates successfully, the relevant scripting feature must be enabled.
          Otherwise, all attempts to create a role mapping with role templates fail.</p>
          <p>All of the user fields that are available in the role mapping rules are also available in the role templates.
          Thus it is possible to assign a user to a role that reflects their username, their groups, or the name of the realm to which they authenticated.</p>
          <p>By default a template is evaluated to produce a single string that is the name of the role which should be assigned to the user.
          If the format of the template is set to &quot;json&quot; then the template is expected to produce a JSON string or an array of JSON strings for the role names.</p>


        `<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-put-role-mapping>`_

        :param name: The distinct name that identifies the role mapping. The name is
            used solely as an identifier to facilitate interaction via the API; it does
            not affect the behavior of the mapping in any way.
        :param enabled: Mappings that have `enabled` set to `false` are ignored when
            role mapping is performed.
        :param metadata: Additional metadata that helps define which roles are assigned
            to each user. Within the metadata object, keys beginning with `_` are reserved
            for system usage.
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        :param role_templates: A list of Mustache templates that will be evaluated to
            determine the roles names that should granted to the users that match the
            role mapping rules. Exactly one of `roles` or `role_templates` must be specified.
        :param roles: A list of role names that are granted to the users that match the
            role mapping rules. Exactly one of `roles` or `role_templates` must be specified.
        :param rules: The rules that determine which users should be matched by the mapping.
            A rule is a logical condition that is expressed by using a JSON DSL.
        :param run_as:
        
elasticsearch/_sync/client/security.py