You are able to run a SQL query/statement with "echo" command by shell module for the ansible task.
# an example task for sql query/statement
- name: set default schema for user
shell: echo "ALTER ROLE alper SET SEARCH_PATH TO myschema" | psql
become: yes
become_user: postgres