awx icon indicating copy to clipboard operation
awx copied to clipboard

AWX Surveys do not support dictionary variables

Open ksharma-qc opened this issue 1 year ago • 5 comments

Please confirm the following

  • [X] I agree to follow this project's code of conduct.
  • [X] I have checked the current issues for duplicates.
  • [X] I understand that AWX is open source software provided for free and that I might not receive a timely response.
  • [X] I am NOT reporting a (potential) security vulnerability. (These should be emailed to [email protected] instead.)

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

  • [X] UI
  • [ ] UI (tech preview)
  • [ ] API
  • [ ] Docs
  • [ ] Collection
  • [ ] CLI
  • [ ] Other

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

ksharma-qc avatar Feb 08 '24 14:02 ksharma-qc

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?

fosterseth avatar Feb 14 '24 16:02 fosterseth

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.

ksharma-qc avatar Feb 14 '24 17:02 ksharma-qc

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

fosterseth avatar Feb 14 '24 21:02 fosterseth

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.

jon-nfc avatar Feb 18 '24 03:02 jon-nfc

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!

jacobemery avatar Apr 29 '24 18:04 jacobemery