I am writing an ansible playbook.
I have the following task
- name: query on server_app - look for items_invoiced
community.postgresql.postgresql_query:
login_host: '{{ db_host }}'
login_user: '{{ db_username }}'
login_password: '{{ db_password }}'
db: '{{ db_database }}'
port: '{{ db_database_port }}'
query: "{{ lookup('template', 'extract_items_invoiced__hourly.sql.j2') }}"
register: items_invoiced
the content of extract_items_invoiced__hourly.sql.j2
is
select hour_payment, * from my_table
where my_table.hour_payment is a time without time zone
object.
As the playbook runs, the following Traceback is raised
query on server_app - look for items_invoiced...
Using module file /home/my_user/var/NTTDATA/4store/ansible-venv/lib/python3.7/site-packages/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py
Pipelining is enabled.
<10.133.4.100> ESTABLISH SSH CONNECTION FOR USER: my_user
<10.133.4.100> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="/home/my_user/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="my_user"' -o ConnectTimeout=10 -o ControlPath=/home/my_user/.ansible/cp/a7034d48db 10.133.4.100 '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<10.133.4.100> (1, b'', b'Traceback (most recent call last):n File "<stdin>", line 102, in <module>n File "<stdin>", line 94, in _ansiballz_mainn File "<stdin>", line 40, in invoke_modulen File "/usr/lib/python2.7/runpy.py", line 188, in run_modulen fname, loader, pkg_name)n File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_coden mod_name, mod_fname, mod_loader, pkg_name)n File "/usr/lib/python2.7/runpy.py", line 72, in _run_coden exec code in run_globalsn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 524, in <module>n File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 520, in mainn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2200, in exit_jsonn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2193, in _return_formattedn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 420, in remove_valuesn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 397, in _remove_values_conditionsnTypeError: Value of unknown type: <type 'datetime.date'>, 2024-04-17n')
<10.133.4.100> Failed to connect to the host via ssh: Traceback (most recent call last):
File "<stdin>", line 102, in <module>
File "<stdin>", line 94, in _ansiballz_main
File "<stdin>", line 40, in invoke_module
File "/usr/lib/python2.7/runpy.py", line 188, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 524, in <module>
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 520, in main
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2200, in exit_json
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2193, in _return_formatted
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 420, in remove_values
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 397, in _remove_values_conditions
TypeError: Value of unknown type: <type 'datetime.date'>, 2024-04-17
The full traceback is:
Traceback (most recent call last):
File "<stdin>", line 102, in <module>
File "<stdin>", line 94, in _ansiballz_main
File "<stdin>", line 40, in invoke_module
File "/usr/lib/python2.7/runpy.py", line 188, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 524, in <module>
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 520, in main
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2200, in exit_json
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2193, in _return_formatted
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 420, in remove_values
File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 397, in _remove_values_conditions
TypeError: Value of unknown type: <type 'datetime.date'>, 2024-04-17
server_app failed: {
"changed": false,
"module_stderr": "Traceback (most recent call last):n File "<stdin>", line 102, in <module>n File "<stdin>", line 94, in _ansiballz_mainn File "<stdin>", line 40, in invoke_modulen File "/usr/lib/python2.7/runpy.py", line 188, in run_modulen fname, loader, pkg_name)n File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_coden mod_name, mod_fname, mod_loader, pkg_name)n File "/usr/lib/python2.7/runpy.py", line 72, in _run_coden exec code in run_globalsn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 524, in <module>n File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_query.py", line 520, in mainn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2200, in exit_jsonn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 2193, in _return_formattedn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 420, in remove_valuesn File "/tmp/ansible_community.postgresql.postgresql_query_payload_pOF_WY/ansible_community.postgresql.postgresql_query_payload.zip/ansible/module_utils/basic.py", line 397, in _remove_values_conditionsnTypeError: Value of unknown type: <type 'datetime.date'>, 2024-04-17n",
"module_stdout": "",
"msg": "MODULE FAILUREnSee stdout/stderr for the exact error",
"rc": 1
}
So ansible is telling me that its python modules cannot recognize the datetime.date
type
TypeError: Value of unknown type: <type 'datetime.date'>, 2024-04-17
could it be that there is a bug in the library?
Fot rhe moment, I have solved by casting the time without time zone
to TEXT
via sql
select hour_payment::text, * from my_table