# set\_fact undefined variable issue when concat string to itself.

**URL:** <https://forum.ansible.com/t/set-fact-undefined-variable-issue-when-concat-string-to-itself/32327>\
**Category:** Ansible Project\
**Created:** [February 26, 2020, 6:30am UTC](https://forum.ansible.com/t/set-fact-undefined-variable-issue-when-concat-string-to-itself/32327 "2020-02-26T06:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [February 26, 2020, 6:30am UTC](https://forum.ansible.com/t/set-fact-undefined-variable-issue-when-concat-string-to-itself/32327/1 "2020-02-26T06:30:42Z")

</div>

I need to set\_fact variable and contact to itself a list of items as below:

`

- set\_fact:  
excludefolders: “{{ excludefolders + ’ -o -name ’ + item | default(‘’) }}”  
with\_items: “{{ lookup(‘vars’, ‘MY\_’ + Layer).split(‘,’) }}”  
`

Getting error:

```auto
FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'excludefolders' is undefined\n\nThe error appears to be in '/app/test.yml': line 86, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - set_fact:\n ^ here\n"}

```

Is it neccessary to defined another set\_fact before like below or is there a better solution to the issue ?

`

- set\_fact:  
excludefolders: “”

- set\_fact:  
excludefolders: “{{ excludefolders + ’ -o -name ’ + item | default(‘’) }}”  
with\_items: “{{ lookup(‘vars’, ‘EXCLUDE\_’ + Layer).split(‘,’) }}”

`

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [February 26, 2020, 6:38am UTC](https://forum.ansible.com/t/set-fact-undefined-variable-issue-when-concat-string-to-itself/32327/2 "2020-02-26T06:38:42Z")

</div>

You can try this -

- set\_fact:  
excludefolders: “{{ excludefolders | default(‘’) + ’ -o -name ’ + item | default(‘’) }}”  
with\_items: “{{ lookup(‘vars’, ‘EXCLUDE\_’ + Layer).split(‘,’) }}”

---

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [February 26, 2020, 9:21am UTC](https://forum.ansible.com/t/set-fact-undefined-variable-issue-when-concat-string-to-itself/32327/3 "2020-02-26T09:21:29Z")

</div>

It helped. Thank you @Abhijeet
