# How can append values into host variable

**URL:** <https://forum.ansible.com/t/how-can-append-values-into-host-variable/19796>\
**Category:** Ansible Project\
**Created:** [November 18, 2015, 4:59pm UTC](https://forum.ansible.com/t/how-can-append-values-into-host-variable/19796 "2015-11-18T16:59:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elad\_Yosef](https://avatars.discourse-cdn.com/v4/letter/e/3ec8ea/32.png) [@Elad\_Yosef](https://forum.ansible.com/u/Elad_Yosef)\
**Post date:** [November 18, 2015, 4:59pm UTC](https://forum.ansible.com/t/how-can-append-values-into-host-variable/19796/1 "2015-11-18T16:59:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [November 19, 2015, 10:17pm UTC](https://forum.ansible.com/t/how-can-append-values-into-host-variable/19796/2 "2015-11-19T22:17:11Z")

</div>

Try

- set\_fact: locked\_domains="{{ locked\_domains }}item.ID"

Also using with\_dict might be better option instead of with\_items in this case.
