# Copy with\_fileglob Regex doesn't work

**URL:** <https://forum.ansible.com/t/copy-with-fileglob-regex-doesnt-work/29263>\
**Category:** Ansible Project\
**Created:** [December 14, 2018, 11:23am UTC](https://forum.ansible.com/t/copy-with-fileglob-regex-doesnt-work/29263 "2018-12-14T11:23:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@Phillip](https://forum.ansible.com/u/Phillip)\
**Post date:** [December 14, 2018, 11:23am UTC](https://forum.ansible.com/t/copy-with-fileglob-regex-doesnt-work/29263/1 "2018-12-14T11:23:58Z")

</div>

Hi All

I searched for a solution but everything I found didn’t helped.  
We catch up all pub.key files from servers when we connect and then we would like to deploy them to the correct enviroment.

Here the config:

- name: copy all needed pub.key files from deployuser  
copy:  
src: “{{ item }}”  
dest: /tmp/  
with\_fileglob:
- /opt/ansible/playbooks/roles/tdInfra/files/ssh\_public\_keys/_{{ tdInfraKey|upper }}_

We have different enviroments, dev and prod. The Files have the hostname in the name with …PROD… or …DEV…  
So I tryed to match them with |upper which works fine to bring those letters up.  
When I do a:

- debug: var=tdInfraKey

This is the outpu:

ok: [host.td.infra.sys] =\> {  
“tdInfraKey”: [  
“dev”  
]  
}

With the configuration I have posted on top the matching does not work and it find all files with a D in the first position.

user@DEV001.domain.local  
user@DLOG051.domain.local

user@DEV401.domain.local

user@LOOP031.domain.local

I have no clue anymore where the issue could come from. So I would be very thankful if anybody could help me with an idea.

OS: CentOS7  
Ansible Version: 2.4.2.0-2.el7

Thank you and kind regards,  
Phillip

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 14, 2018, 2:41pm UTC](https://forum.ansible.com/t/copy-with-fileglob-regex-doesnt-work/29263/2 "2018-12-14T14:41:06Z")

</div>

Your tdInfraKey is a list with one element, so to get the value you need to specify the first element.

{{ tdInfraKey.0|upper }}

---

<div class="post-metadata">

**Author:** ![Phillip](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@Phillip](https://forum.ansible.com/u/Phillip)\
**Post date:** [December 14, 2018, 3:56pm UTC](https://forum.ansible.com/t/copy-with-fileglob-regex-doesnt-work/29263/3 "2018-12-14T15:56:37Z")

</div>

Thank you Kai!!  
I was searching for hours!

Well, stupid problem as a newbie in Ansible but thank you very much.
