The 'when' property seems not working in 'select_one' type

From the documentation:

The when property can be used on groups, items, and select_one options.

But seems it’s not working on ‘select_one’ options or I misunderstood this.
I have code:

- name: postgres_host_type
  type: select_one
  title: Postgres Host Type
  default: postgres_hostname
  items:
    - name: postgres_hostname
      title: Postgres Hostname
    - name: postgres_ip
      title: Postgres IP Adress
    - name: embedded_postgres
      title: Embeded Postgres
      when: '{{repl (ConfigOptionEquals "dev_deploy" "true")}}'

I want last option ‘embedded_postgres’ will be shown only when property “dev_deploy” is “true”, but it’s shown always, no matter “dev_deploy” is “true” or “false”. What the proper way to achieve this?

I’ve found one post here in community but without answer. Select_one and "when"

The word item is overloaded—items are used at the top level (i.e., postgres_host_type is an item) and then there are items for the select_one. The when doesn’t work for the items in the select_one. It only works at the top level (if I recall correctly).

So to accomplish this today, you would have to create two select_one items. One would have the “Embedded Postgres” option and one would not. Then you would use when on each of those two items so that the proper select_one shows based on the value of dev_deploy.

Something like this (not verifying syntax, so check this before using):

- name: postgres_host_type
  type: select_one
  title: Postgres Host Type
  default: postgres_hostname
  when: '{{repl (ConfigOptionEquals "dev_deploy" "true")}}'
  items:
    - name: postgres_hostname
      title: Postgres Hostname
    - name: postgres_ip
      title: Postgres IP Adress
    - name: embedded_postgres
      title: Embeded Postgres
- name: postgres_host_type
  type: select_one
  title: Postgres Host Type
  default: postgres_hostname
  when: '{{repl (ConfigOptionNotEquals "dev_deploy" "true")}}'
  items:
    - name: postgres_hostname
      title: Postgres Hostname
    - name: postgres_ip
      title: Postgres IP Adress
1 Like

So, it looks like that documentation is not clear enough (at least for me). It says about ‘groups’ (we can make groups optional with ‘when’), about ‘items’, and about select_one options.

You’re right, the docs do say that. Someone else asked about this recently, so maybe there’s a regression here. Can you open a support case so that we can investigate and fix if needed or update the docs?

Thank you Alex. I will create support ticket