-
Notifications
You must be signed in to change notification settings - Fork 111
Description
SUMMARY
We are using a playbook task to run an SQL file that is generated by a PHP script. The PHP script uses file_put_contents() to create the .sql file based upon an array of queries (could be any number of queries). All queries end with a semicolon. The file is generated with a \n at the end of the file every time, and there is no way to generate the file without it. Whenever I run the task, I receive a fatal error (Cannot execute SQL '' None: can't execute an empty query). The only way to solve this is to open up the .sql file in an editor, delete the \n character, and run the playbook again.
I tried everything I can think of to attempt to trim that \n during the file generation, but no luck. Hoping you all can help or confirm this is a feature not a bug.
ISSUE TYPE
- Bug Report
COMPONENT NAME
postgresql_query
ANSIBLE VERSION
ansible [core 2.11.7]
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ahart/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
ansible collection location = /home/ahart/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]
jinja version = 2.11.3
libyaml = False
COLLECTION VERSION
# /usr/local/lib/python2.7/dist-packages/ansible_collections
Collection Version
-------------------- -------
community.postgresql 1.6.0
CONFIGURATION
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 100
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False
DISPLAY_SKIPPED_HOSTS(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT
Debian 10
PHP 7.4
Python 2.7 ( cannot upgrade to Python 3 yet on this server)
STEPS TO REPRODUCE
Generate a text file containing a couple of postgres queries in PHP with file_put_contents(). Open the file in an editor and note that it contains a new line at the end of the file.
Run a playbook that contains the following simple task:
- name: Testing postgres query with path_to_script
become: true
become_user: postgres
postgresql_query:
db: "db_name"
path_to_script: "path/to/generated/script"EXPECTED RESULTS
Task finishes with no fatal error and queries from our file have been run successfully.
ACTUAL RESULTS
The task fails with a fatal error due to the query list having a blank query in it.
fatal: [hostname.goes.here]: FAILED! => {"changed": false, "msg": "Cannot execute SQL '' None: can't execute an empty query, query list: [\"UPDATE users SET mfa_enabled=true WHERE login='login_name_1'\", \"\\nUPDATE users SET mfa_enabled=true WHERE login='login_name_2'\", '']"}
(I've cleaned the resulting error message of our data.)
Thanks for any assistance you can offer!