How can append values into host variable

Hi all,

I’m very new to ansible and sorry if the question is too easy

I have defined host_var

locked_domains:

And I want to append values to it from a task

  • set_fact: locked_domains=“{{ locked_domains + item.ID }}”
    when: {{item.state}} == “some_cond”
    with_items: “{{ domains.json }}”

where domains.json is an array of objects

I get the following error

fatal: [localhost] => Failed to template locked_domains=“{{ locked_domains + item.ID }}”: an unexpected type error occurred. Error was unsupported operand type(s) for +: ‘NoneType’ and ‘str’

FATAL: all hosts have already failed – aborting

Please advise

Thanks

Elad

Try

- set_fact: locked_domains="{{ locked_domains }}item.ID"

Also using with_dict might be better option instead of with_items in this case.