from ansible.errors import AnsibleFilterTypeError
from ansible.module_utils.six import string_types


# Ansible's "quote" filter is only applied to shell module
def quote_single(str):
    """
    Quote a string with single quote.

    Example: a string -> 'a string'
    """
    if isinstance(str, string_types):
        return "'" + str + "'"
    else:
        raise AnsibleFilterTypeError(
            "|quote_single expects string, got %s instead." % type(str))


class FilterModule(object):
    """Custom Ansible jinja2 filters for sysconfig playbook."""

    def filters(self):
        return {'quote_single': quote_single}
