How can append values into host variable

30 views
Skip to first unread message

Elad Yosef

unread,
Nov 18, 2015, 5:33:08 PM11/18/15
to Ansible Project
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

Igor Cicimov

unread,
Nov 19, 2015, 5:17:11 PM11/19/15
to Ansible Project
Try

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

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

Reply all
Reply to author
Forward
0 new messages