-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postgresql_query is not able use variable list as postgreSQL array #59955
Comments
Files identified in the description: If these files are inaccurate, please update the |
Files identified in the description: If these files are inaccurate, please update the |
@mullaiarasu , thank you for reporting this! |
@mullaiarasu , i've checked it.
The best way to pass arrays/json/etc. is just to use quotes and braces inside them, e.g.:
it works well. |
needs_info |
I added an example to the module documentation #59979 |
Hi Andersson, I appreciate your help you have suggested, also I have already defined the variable like this and found working, this condition works better in static variables but however when you have dynamic variable list from task output the list looks like ['1','2','3'] I am not able to convert to '{1,2,3}'. I was able to format it like 1,2,3 using string manipulation with join command however I am not able to convert ['1','2','3'] into '{1,2,3}' as ansible wont allow to add curly braces as it impacts the formatting itself i manged to string manipulate like [ 1,2,3] but it also don't work. so can you please let me know how should I convert a ansible (python) list into psql array |
@mullaiarasu , np, i’ll answer a bit later. My phone doesn’t allow me to use correct formatting, sorry. Not near the PC right now. |
@mullaiarasu , i'm not a guru of jinja template syntax but in pythonic code we could use roughly something like:
|
Hi Andrey,
As you have suggested I have created I tired created python script to
convert list from [ 1,2,3] to {1,2,3} but when try read that variable into
ansible to pass positional args I get an error JINJA format set not
defined. I shared different types of error I received in my issue.
…On Mon, Aug 5, 2019 at 11:59 AM Andrey Klychkov ***@***.***> wrote:
@mullaiarasu <https://github.com/mullaiarasu> , i'm not a guru of jinja
template syntax but in pythonic code we could use roughly something like:
>>> my_list = [1, 2, 3]
>>> my_pg_array = '{' + str(my_list).strip('[]') + '}'
>>> my_pg_array
'{1, 2, 3}'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#59955?email_source=notifications&email_token=AE4I3RXJETX7JQIR4X4MFMDQDB2B7A5CNFSM4IIWH5ZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3SX5XQ#issuecomment-518356702>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE4I3RXWURTDFL7HSRPD2ULQDB2B7ANCNFSM4IIWH5ZA>
.
|
@mullaiarasu , could you please give the full code and error messages? initially, I tried to pass
Please note that it must be a string.
|
we also must convert my_var to string
waiting for your feedback |
Yes by defining the variable '{{my_var|string}}' it works good hack :) but is there also way to a append curly braces in the ansible itself instead of using python script |
@mullaiarasu , yep, the problem is obviously because:
I cought that too, be sure:
|
@mullaiarasu , sorry, i didn't see you added a new comment while i was writing my previous comment |
I tried to find something for that before but failed, for example cookiecutter/cookiecutter#11. However it doesn't work for the second brace, I have no clue why. |
Yup you can close the issue , but it would nice if postgresql_query can accept list but I do understand the postgress array is different than a python list. Thanks for prompt support really appreciate it Let me know you if want me to close the issue |
Nps, don’t close the issue for a while. I’ll see again maybe this week |
@mullaiarasu hey, #60559 please, look |
SUMMARY
I am not able to use the variable list as postgreSQL array argument in the psql query
PostgreSQL accept array in format '{16367,15820,15865,15869}'
On manipulating variable list [6367,15820,15865,15869] into '{16367,15820,15865,15869}' using customized script and when try to pass as argument will receive below error
Unable to pass options to module, they must be JSON serializable: set([15865, 15820, 15869, 16367]) is not JSON serializable"
ISSUE TYPE
On trying to use the variable list [15865, 15820, 15869, 16367] below error is received
On trying to use the variable string "15865, 15820, 15869, 16367" below error is received
COMPONENT NAME
lib/ansible/modules/database/postgresql/postgresql_query.py
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
RHEL7
STEPS TO REPRODUCE
using list variable list in positional_args or named_args for postgresql_query to select , update or delete will reproduce the issue
EXPECTED RESULTS
I
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: