# authorized\_keys with fileglob

**URL:** <https://forum.ansible.com/t/authorized-keys-with-fileglob/14171>\
**Category:** Ansible Project\
**Created:** [December 17, 2013, 7:12pm UTC](https://forum.ansible.com/t/authorized-keys-with-fileglob/14171 "2013-12-17T19:12:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [December 17, 2013, 7:12pm UTC](https://forum.ansible.com/t/authorized-keys-with-fileglob/14171/1 "2013-12-17T19:12:03Z")

</div>

Hi,

I'm trying to setup authorized\_keys without copying the key files over to the target.

When I do this it works:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: populate authorized\_keys  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;authorized\_keys: user=blah key={{item}} state=present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_file:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- grant/x.pub  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- grant/y.pub

But when I try the following:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: populate authorized\_keys  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;authorized\_keys: user=blah key={{item}} state=present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_filegob:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- grant/\*

I get "failed: "true", item: "/home/yves/xxxx/roles/sshkeys/files/grant/x.pub", msg: invalid key specified

Does that mean that with\_fileglob sends the name of the file rather than the content of the file?

How can I make with\_file lookup a list of files? Or how can I make with\_fileglob copy the content of the files?

Thanks

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 17, 2013, 7:29pm UTC](https://forum.ansible.com/t/authorized-keys-with-fileglob/14171/2 "2013-12-17T19:29:39Z")

</div>

> Does that mean that with\_fileglob sends the name of the file rather than  
> the content of the file?

Yes.​​

> How can I make with\_file lookup a list of files? Or how can I make  
> with\_fileglob copy the content of the files?

​make that

key="{{ lookup('file', item) }}"​

​Serge​

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [December 17, 2013, 7:35pm UTC](https://forum.ansible.com/t/authorized-keys-with-fileglob/14171/3 "2013-12-17T19:35:22Z")

</div>

I saw that online, tried it, but this assumes that I copy all my key files over to the target (I'm getting "does not exist"), which I am trying to avoid.

Is there a way to do something like:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_file:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- {{ lookup 'grant/\*' }}

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 17, 2013, 7:46pm UTC](https://forum.ansible.com/t/authorized-keys-with-fileglob/14171/4 "2013-12-17T19:46:27Z")

</div>

No, that must be another problem then. Lookup plugins allways act on the  
localhost (where you run ansible-playbook).​

Serge

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [December 18, 2013, 5:15am UTC](https://forum.ansible.com/t/authorized-keys-with-fileglob/14171/5 "2013-12-18T05:15:58Z")

</div>

Thanks!

There was a funny character in the file names which "with\_file" handled fine, but with\_fileglob didn't. Adding double quotes around the item solved the issue:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;authorized\_key: user=blah key="{{ lookup('file', "item") }}
