Copy with_fileglob Regex doesn't work

15 views
Skip to first unread message

Phillip

unread,
Dec 14, 2018, 6:23:58 AM12/14/18
to Ansible Project
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.

us...@DEV001.domain.local
us...@DLOG051.domain.local
us...@DEV401.domain.local
us...@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

Kai Stian Olstad

unread,
Dec 14, 2018, 9:41:40 AM12/14/18
to ansible...@googlegroups.com
On Friday, 14 December 2018 12:23:58 CET Phillip wrote:
> 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"
> ]
> }

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

{{ tdInfraKey.0|upper }}


--
Kai Stian Olstad


Phillip

unread,
Dec 14, 2018, 10:56:37 AM12/14/18
to Ansible Project
Thank you Kai!!
I was searching for hours!

Well, stupid problem as a newbie in Ansible but thank you very much.
Reply all
Reply to author
Forward
0 new messages