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 151 forks source link

Deny parsing YAML variables if not a dict #564

Open AlanCoding opened 6 years ago

AlanCoding commented 6 years ago

Bug discovered from mailing list:

tower-cli host modify -n host1 --variables "ansible_python_interpreter=/usr/bin/python26" -v
*** DETAILS: Checking for an existing record. *********************************
GET http://localhost:8013/api/v2/hosts/
Params: {'name': u'host1'}

*** DETAILS: Writing the record. **********************************************
PATCH http://localhost:8013/api/v2/hosts/16/
Data: {'name': u'host1', 'variables': u'ansible_python_interpreter=/usr/bin/python26'}

Error: The Tower server claims it was sent a bad request.

PATCH http://localhost:8013/api/v2/hosts/16/
Params: None
Data: {"name": "host1", "variables": "ansible_python_interpreter=/usr/bin/python26"}

Response: {"variables":["Cannot parse as JSON (error: No JSON object could be decoded) or YAML (error: Input type `str` is not a dictionary)."]}

It actually looks like this is kind of intentional, because the host model uses the Variables type instead of the StructuredInput type, meaning that it passes the variables as they are to the server, and does not accommodate the key=value syntax.

AlanCoding commented 6 years ago

Same issue as https://github.com/ansible/tower-cli/issues/574

AlanCoding commented 6 years ago

In modules, variables are handled here:

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py#L95

So it never passes the field with the "@" to signify lookup.

extra_vars may do that

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py#L222

Actually, it looks like the modules only accepts extra_vars from a file. That's weird.