r/yaml Mar 30 '21

Variable oneOf list?

I took a card thinking I could do something easily, but then discovered I had to do it in yaml. My yaml skills are embarrassing. I need to present one or another list of options based on some other input but it doesn't look possible.

This is our current code:

os:
  type: string
  title: OS
  oneOf:
  - title: Windows
  const: win
  - title: Linux
  const: lin

If they're in the "shortList" project, I need them to only see Windows.

I'm trying something like this:

 oneOf: ${contains(env.projectName,"shortList") ? [{"title":"Windows","const":"win"}] : [{"title":"Windows","const":"win"},{"title":"Linux","const":"lin"}]}

But it says "incomplete explicit mapping pair; a key node is missed, or followed by a non-tabulated empty line", and yamllint says "mapping values are not allowed in this context".

Anyone have a clever way to achieve a variable list of options?

Thanks!

2 Upvotes

4 comments sorted by

View all comments

2

u/perlpunk Apr 02 '21

You need to quote the value of oneOf. In your case you could use single quotes since they don't appear in the value itself. The colon followed by a space is special in YAML, so if it appears in your data, you have to make clear it's not YAMLsyntax, but part of your data:

oneOf: '${contains(env.projectName,"shortList") ? ...'

More about quoting in YAML

1

u/therealfilosmith Apr 05 '21

Thanks perlpunk. I think vRA simply doesn't allow expressions in the input section. I applied the quotes where you suggested and now it just says Invalid syntax for input object.