authorized_keys with fileglob

Hi,

I'm trying to setup authorized_keys without copying the key files over to the target.

When I do this it works:

     - name: populate authorized_keys
       authorized_keys: user=blah key={{item}} state=present
       with_file:
         - grant/x.pub
         - grant/y.pub

But when I try the following:

     - name: populate authorized_keys
       authorized_keys: user=blah key={{item}} state=present
       with_filegob:
         - 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

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​

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:
     with_file:
       - {{ lookup 'grant/*' }}

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

Serge

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:

     authorized_key: user=blah key="{{ lookup('file', "item") }}