ansible / tower-cli

THIS TOOL IS NO LONGER UNDER ACTIVE DEVELOPMENT. This tool is being phased out in favor of the new official AWX CLI
https://github.com/ansible/awx/tree/devel/awxkit/awxkit/cli/docs
Apache License 2.0
361 stars 150 forks source link

Allow numeric strings in extra-vars #254

Open tomfotherby opened 7 years ago

tomfotherby commented 7 years ago

Today I upgraded Tower from v3.0.2 to v3.1.0 and my tower-cli job launches started failing.

It seems Tower 3.1 has some new type checks and now doesn't like getting integers in extra-vars. This is a example of the new error:

$ tower-cli job launch --job-template=666 --extra-vars="version=15601 githubuser=tomfotherby"
Error: The Tower server claims it was sent a bad request.

POST https://tower.example.com/api/v1/job_templates/666/launch/
Params: None
Data: {"extra_vars": "{\"version\": 15601, \"githubuser\": \"tomfotherby\"}"}

Response: {"variables_needed_to_start":["Value 15601 for 'version' expected to be a string."]}

I found a workaround was to use yml syntax to specify the extra var as a string explicitly.

$ tower-cli job launch --job-template=666 --extra-vars="{'version':'15601'}" --extra-vars="githubuser=tomfotherby"
Resource changed.
===== ============ ======================== ======= ======== 
 id   job_template         created          status  elapsed  
===== ============ ======================== ======= ======== 
11166           666 2017-03-02T15:32:57.323Z running 0.487649
===== ============ ======================== ======= ======== 

It would be great if tower-cli supported a syntax where you can tell it that integers should be treated as strings. for example, using quotes:

$ tower-cli job launch --job-template=666 --extra-vars="version='15601' githubuser=tomfotherby"

I wanted to contact Ansible support about this change in Tower, but the website isn't working ( https://support.ansible.com/hc/en-us ).

AlanCoding commented 7 years ago

Value 15601 for 'version' expected to be a string.

Got it. This happens in the scenario where the survey has a variable that is type "Text" and you give it this type of input.

The burden here is on tower-cli, because Tower UI will automatically coerce the data into text. Tower-cli should do the same.

Support should point to https://access.redhat.com/products/ansible-tower-red-hat/, and any links that persist to the old page need to be changed. Thanks for bringing that to our attention.

tomfotherby commented 7 years ago

@AlanCoding - Yes, you are right, thank you. I used Tower to edit the Survey of the Job template to change "Answer Type" from Text to Float. Then my tower-cli commands started working again. Good stuff.

(feel free to close this issue if you feel it's not relevant)

AlanCoding commented 7 years ago

This may get re-evaluated whenever additional survey work is done, because I'm not sure how intrusive type checking will be.

One support link fixed in https://github.com/ansible/ansible/pull/22212

sebastiangraf commented 7 years ago

We got exactly the same issue with the upgrade of Tower to 3.0.x to 3.1.x. In our case, we are posting arrays to the tower:

[u217229@svn_to_git_worker-int-i ~]$ tower-cli job launch --job-template=gsharp_DiDok_GEO-INT_deploy-webapp '--extra-vars=findAndReplaceValues: [{'\''source'\'' : '\''app.*.js'\'', '\''find'\'' : '\''geo-int'\'', '\''replace'\'' : '\''geo-int'\''}, {'\''source'\'' : '\''app.*.js'\'', '\''find'\'' : '\''geo-dev'\'', '\''replace'\'' : '\''geo-int'\''},  {'\''source'\'': '\''app.*.js'\'', '\''find'\'':'\''Dienststellen_temp'\'', '\''replace'\'':'\''Dienststellen'\''},  {'\''source'\'': '\''app.*.js'\'', '\''find'\'':'\''useArcGISToken:true'\'', '\''replace'\'':'\''useArcGISToken:false'\''}]' --monitor
Error: The Tower server claims it was sent a bad request.

POST https://deploy-t.sbb.ch/api/v1/job_templates/3816/launch/
Params: None
Data: {"extra_vars": "{\"webAppName\": \"DiDok\", \"findAndReplaceValues\": [{\"source\": \"app.*.js\", \"find\": \"geo-int\", \"replace\": \"geo-int\"}, {\"source\": \"app.*.js\", \"find\": \"geo-dev\", \"replace\": \"geo-int\"}, {\"source\": \"app.*.js\", \"find\": \"Dienststellen_temp\", \"replace\": \"Dienststellen\"}, {\"source\": \"app.*.js\", \"find\": \"useArcGISToken:true\", \"replace\": \"useArcGISToken:false\"}], \"version\": \"LATEST\", \"groupId\": \"ch.sbb.didok\", \"artifactId\": \"didokjs\"}"}

Response: {"variables_needed_to_start":["Value [{u'source': u'app.*.js', u'find': u'geo-int', u'replace': u'geo-int'}, {u'source': u'app.*.js', u'find': u'geo-dev', u'replace': u'geo-int'}, {u'source': u'app.*.js', u'find': u'Dienststellen_temp', u'replace': u'Dienststellen'}, {u'source': u'app.*.js', u'find': u'useArcGISToken:true', u'replace': u'useArcGISToken:false'}] for 'findAndReplaceValues' expected to be a string."]}

The parameter in the survey is a TextArea. Is there any way to post arrays with the help of the tower-cli? Or should we rely on REST?

Ansible Support in Case 01869195 cross-checked against this issue and they came to the conclusion as well, that the burden is on site of the tower-cli.

mauricios commented 7 years ago

I ran into the same issue when using numeric strings in a survey field which validates to Text. I've solved this issue by sending extra vars in JSON format so I can enforce numeric strings to be strings.