Skip to content

Instantly share code, notes, and snippets.

@cans
Last active July 2, 2019 19:47
Show Gist options
  • Save cans/165ecb5042e8c45b6cd5db18227f1c1f to your computer and use it in GitHub Desktop.
Save cans/165ecb5042e8c45b6cd5db18227f1c1f to your computer and use it in GitHub Desktop.
A hastly put together filter plugin for postgres identifier (not yet functional)
# A hastly put together filter plugin to try have Ansible's `postgresql_query` module
# deal with identifiers correctly.
# References:
# * Postgres identifiers
# https://www.postgresql.org/docs/11/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
# * Psycopg2 handling of identifiers (cf. last example in the section)
# http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries
from psycopg2 import sql
from ansible.plugins.filter import core
def pgidentifier(value):
core.mandatory(value) # Useful ?
return sql.Identifier(value)
class FilterModule(object):
def filters(self):
return {'pgidentifier': pgidentifier,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment