# create folder adds \[' my var ’\]

**URL:** <https://forum.ansible.com/t/create-folder-adds-my-var/34068>\
**Category:** Ansible Project\
**Created:** [October 20, 2020, 9:54pm UTC](https://forum.ansible.com/t/create-folder-adds-my-var/34068 "2020-10-20T21:54:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gisbert\_Haas](https://avatars.discourse-cdn.com/v4/letter/g/d07c76/32.png) [@Gisbert\_Haas](https://forum.ansible.com/u/Gisbert_Haas)\
**Post date:** [October 20, 2020, 9:54pm UTC](https://forum.ansible.com/t/create-folder-adds-my-var/34068/1 "2020-10-20T21:54:34Z")

</div>

I have the following regex in my playbook:

- name: get business ID  
set\_fact:  
my\_var: “{{ inventory\_hostname | regex\_findall(‘.+?(?=-).+?(?=-).+?(?=-).+?(?=-)+’) }}”

the debug returns the right value:

ok: [DE-LEI-GRO-GROLE-F001-FW01-MDF] =\> {  
“my\_var”: [  
“DE-LEI-GRO-GROLE”

when using create directory

- name: create directory  
file:  
path: /home/vinn/devicebackups/{{ my\_var }}  
state: directory

its creates the directory adding [’ ’]

“path”: “/home/vinn/devicebackups/[''DE-LEI-GRO-GROLE’]”,

any idea why??

thanks a lot

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 20, 2020, 11:54pm UTC](https://forum.ansible.com/t/create-folder-adds-my-var/34068/2 "2020-10-20T23:54:11Z")

</div>

> I have the following regex in my playbook:  
> &nbsp;&nbsp;&nbsp;- name: get business ID  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set\_fact:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_var: "{{ inventory\_hostname |  
> regex\_findall('.+?(?=-).+?(?=-).+?(?=-).+?(?=-)+') }}"
> 
> the debug returns the right value:
> 
> ok: [DE-LEI-GRO-GROLE-F001-FW01-MDF] =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"my\_var": [  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"DE-LEI-GRO-GROLE"

&nbsp;&nbsp;The bracket '[' tells us the variable my\_var is a list. It's not  
&nbsp;&nbsp;clear how the set\_fact above managed to create the list.

> when using create directory  
> &nbsp;&nbsp;&nbsp;- name: create directory  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: /home/vinn/devicebackups/{{ my\_var }}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: directory
> 
> its creates the directory adding [' ’]
> 
> "path": "/home/vinn/devicebackups/[''DE-LEI-GRO-GROLE’]",
> 
> any idea why??

&nbsp;&nbsp;The variable my\_var is a list.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 21, 2020, 12:04am UTC](https://forum.ansible.com/t/create-folder-adds-my-var/34068/3 "2020-10-21T00:04:57Z")

</div>

The filter regex\_findall returns a list of matches  
[https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/filter/core.py#L137](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/filter/core.py#L137)

---

<div class="post-metadata">

**Author:** ![Gisbert\_Haas](https://avatars.discourse-cdn.com/v4/letter/g/d07c76/32.png) [@Gisbert\_Haas](https://forum.ansible.com/u/Gisbert_Haas)\
**Post date:** [October 21, 2020, 10:24am UTC](https://forum.ansible.com/t/create-folder-adds-my-var/34068/4 "2020-10-21T10:24:33Z")

</div>

thanks

could it be that hyphen - are not allowed in the variable string?
