Open AnnSopVier opened 3 years ago
I just fixed the bug myself. The solution is, that in serializer.py in the class Meta the model JobTemplate has no field 'survey_spec'. After adding 'survey_spec' manually to the two corresponding places in the code the import of surveys via CLI works just fine.
@AnnSopVier sounds like an opportunity for a pull request?
I ran into the same issue, tried adding a survey with both the awx cli tool as well as the job_templates/survey_spec API endpoint. The latter returns a '200 OK', but does not add or update a survey.
I've taken a quick look yesterday evening, I think @AnnSopVier is referring to awx/api/serializers.py instead of 'serialyzer.py'. Tried following the provided instructions, which did not fix the problem for me. Granted, could be I just didn't decipher the provided solution properly. I'll give fixing this another shot asap.
Hi sorry for the not to clear solution of mine :) So what I did was I added "'survey_spec' ," to the awx/api/serializers.py file at two places (see screenshot attached).
. Afterwards I was able to import a survey with "awx job_templates create --name "
In the JsonSurvey I have a simple survey to be imported (see screenshot attached).
(Note the screenshot of the survey is just one of the surveys I import it is not the corresponding survey of the other screenshot ;))
Also of course you need to make sure that the .json with the survey questions is at the described path and the Inventory, Project. Playbook and so on actually exist.
Thanks @AnnSopVier. Can't speak for the AWX CLI client, but my problem with the API seems to be a PEBCAK.. Used '/survey_spec' instead of '/survey_spec/'..
I think maybe what we should do is add new verbs for operations against the related endpoints: related_get
or rget
, related_create
or rcreate
, related_modify
or rmodify
ISSUE TYPE
SUMMARY
ENVIRONMENT
STEPS TO REPRODUCE
Install Ansible and AWX and also CLI. Copy the inventory and the survey.json file in /var/liv/awx/projects/00_NewCustomer of the docker container awx_web. Enter the following commands via the CLI on the docker container awx_web:
All of these steps work and I can see the templates in the UI.
If I now try to add a survey to the job_template (same result for both ways) the survey is not added in the UI and I get the following feedback on the console.
awx job_templates delete --name "00_NewCustomerSurvey_Template"
awx job_templates create --name "00_NewCustomerSurvey_Template" --job_type run --inventory "00_NewCustomerSurvey_Inventory" --project "00_NewCustomerSurvey_Project" --playbook "00_NewCustomerSurvey.yaml" -- survey_spec '{ 'description': 'A survey', 'name': 'my survey' 'spec': [{ 'index': 0, 'question_name': 'What is your department', 'required': False, 'variable': 'department', 'type': 'password', 'max': 3 }], }' --survey_enabled=true
awx job_templates delete --name "00_NewCustomerSurvey_Template"
awx job_templates modify --id "00_NewCustomerSurvey_Template" --survey_spec @/var/lib/awx/projects/00_NewCustomer/survey.json --survey_enable=true
The content of survey.json is:
{ 'description': 'A survey', 'spec': [{ 'index': 0, 'question_name': 'What is your department', 'required': False, 'variable': 'department', 'type': 'password', 'max': 3 }], 'name': 'my survey' }
EXPECTED RESULTS
I would expect that in both cases the one-question-long survey would be imported to the UI
ACTUAL RESULTS
The Job Template is created in both cases but no survey is added. The feedback from the console is in both cases the same (see screenshots attached)
ADDITIONAL INFORMATION
I assume that either I use the commands wrong or the content of the variable survey_spec is not correctly passed to survey_enable.