ansible / awx-resource-operator

43 stars 34 forks source link

Add support for Surveys to JobTemplates #136

Open the-it-jaeger opened 1 year ago

the-it-jaeger commented 1 year ago

I think we should support adding Surveys to JobTemplates

Here are the related parameters from the awx.awx.job_template module

Here's an example of what the YAML from RHCOP's controller_configuration looks like:

    survey_enabled: True
    survey_spec: {'name': '', 'description': '', 'spec': [{'question_name': 'Which bastion host?', 'question_description': '', 'required': True, 'type': 'multiplechoice', 'variable': 'remote_host', 'min': 0, 'max': 1024, 'default': 'server.example.com', 'choices': ['server.example.com'], 'new_question': True}, {'question_name': 'Which user on the bastion host?', 'question_description': "This user's home directory will be searched for the ./secrets directories and files", 'required': True, 'type': 'multiplechoice', 'variable': 'username', 'min': 0, 'max': 1024, 'new_question': False, 'default': '', 'choices': ['user1', 'user2', 'user3', 'user4', 'user5']}, {'question_name': 'Which repository?', 'question_description': 'This repository folder in ~/vscode/ will be searched for ./secrets directories and files', 'required': True, 'type': 'multiplechoice', 'variable': 'repo_name', 'min': 0, 'max': 1024, 'new_question': False, 'default': 'repo1', 'choices': ['repo1']}]}

survey_spec is really messy, so maybe we can make the fields look nicer for users like this:

kind: JobTemplate
...
spec:
...
  survey_enabled: true
  survey_spec:
    questions:
      - name: Which thing do you want?
        description: Pick your favorite thing
        required: true
        type: multiplechoice
        choices:
          - thing1
          - thing2
          - thing3
        default: thing1
        variable: thing_var
      - name: Where do you want it?
        description: Pick your favorite place
        required: true
        type: multiplechoice
        choices:
          - place1
          - place2
          - place3
        default: place1
        variable: place_var
      - name: What is your favorite color?
        description: This one is optional
        required: false
        type: text
        variable: color_var

The TowerAPI seems to treat survey_spec as a separate thing that gets related to job_templates. We could create a new JobTemplateSurveySpec API, but it would probably be harder to implement this because it would introduce dependencies on the JobTemplate API and whatever objects may or may not already be defined on a cluster. šŸ¤”

Does anyone have any thoughts or opinions on this?