ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.66k stars 3.37k forks source link

AWX Surveys do not support dictionary variables #14860

Open ksharma-qc opened 4 months ago

ksharma-qc commented 4 months ago

Please confirm the following

Bug Summary

Variable dictionaries are supported in the Template variables and can be passed just fine as follows:

---
inputs:
  region_code: uk
  client_code: some_code
  app_version: 1.1-beta-997

However, if a survey is created with variable name inputs.region_code as follows: image

Then AWX complains that the field is blank despite specifying values: image

Given that Ansible supports nested variable dictionaries, and such variables can be passed from commandline or in Template definitions, the Survey should also support it so that existing Playbooks can be used rather than requiring them to be refactored to work with Surveys.

AWX version

23.7.0

Select the relevant components

Installation method

kubernetes

Modifications

no

Ansible version

No response

Operating system

No response

Web browser

Firefox, Chrome, Safari, Edge

Steps to reproduce

Try to override a nested variable from a Survey

Expected results

Values provided in Survey should be accepted and passed to the Playbook

Actual results

UI complains that the field is empty/missing

Additional information

No response

fosterseth commented 4 months ago

thanks for outlining these details. I guess one workaround for now is to use a non-dictionary variable for those variables you want set by the survey form

@mabashian do you know if the expectation is the survey value to be injected into a dictionary? is this fixed in the new UI?

ksharma-qc commented 4 months ago

thanks for outlining these details. I guess one workaround for now is to use a non-dictionary variable for those variables you want set by the survey form

@mabashian do you know if the expectation is the survey value to be injected into a dictionary? is this fixed in the new UI?

New UI? I'm currently at the latest version of AWX.

The problem with workaround is that'll require me to modify the code for playbooks which haven't been written by me.

The expectation is for the values to be injected into the dictionary yes. inputs.a.b should translate to:

inputs:
  a:
     b:

Furthermore, the dictionary should be merged into any existing ones if ANSIBLE_HASH_BEHAVIOUR is set to merge.

fosterseth commented 4 months ago

@ksharma-qc thanks, yes sounds like a bug that would need some UI work to address

jon-nfc commented 4 months ago

Just discovered this issue and without even knowing it, I have this problem and didn't realize it was due the variable to set being a dict key. in my case module_database.name

I thought there was a bug in the UI for having require: true, so un-checked it for the survey question and now the survey gives no errors and the job template runs as it should. I just can't make the question mandatory.

jacobemery commented 2 months ago

Also found this to be true. The default values appear in the survey summary and can be curl'd, but they don't pre-populate in the survey.

The workaround provided by @fosterseth isn't suitable for me either, as the playbook was written by someone else. I could go through the process of opening a PR and changing all their variables to strings... but with a lot of variables, that's kinda rough and the author may not like that.

I know there's a new UI coming soon, is this is being worked on? I took a peak at the tech preview, but the survey screen is unavailable at the moment, so it's hard to tell.

Thanks!