# extending authorized\_key module

**URL:** <https://forum.ansible.com/t/extending-authorized-key-module/12471>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [March 8, 2013, 10:13pm UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471 "2013-03-08T22:13:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 8, 2013, 10:13pm UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471/1 "2013-03-08T22:13:57Z")

</div>

Ok, so I'm a bit confused here as to what you're trying to achieve exactly.

If you want to set the ownership of the file (like you can do from  
copy/template), we've got some common code we can add -- see what's  
done with the copy module -- and that's a super easy way to achieve  
that.

That seems like what you want?

--Michael

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [March 9, 2013, 3:01am UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471/2 "2013-03-09T03:01:15Z")

</div>

So I noticed that I didn’t complete a sentance in my previous explanation.

By changing this setting to use /etc/ssh/authorized\_keys/%u we are able to distribute everyone’s keys, but placing them outside their home directory. /etc/ssh/authorized\_keys is then owned by root: with mode 755.

I’m not sure what else would be unclear, but will gladly discuss and explain myself further if need be.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 9, 2013, 3:42am UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471/3 "2013-03-09T03:42:04Z")

</div>

> So I noticed that I didn't complete a sentance in my previous explanation.
> 
> By changing this setting to use /etc/ssh/authorized\_keys/%u we are able to  
> distribute everyone's keys, but placing them outside their home directory.  
> /etc/ssh/authorized\_keys is then owned by root: with mode 755.

See my previous response about how we want to handle setting the mode.

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [March 9, 2013, 4:02am UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471/4 "2013-03-09T04:02:01Z")

</div>

So... in the attached conversation I point out the flaw in utilizing an  
external reference to the copy command. Effectively a bunch of extraneous  
mode changing is/will be occurring.

For instance:

- name: ensure that shared authorized\_keys directory exists  
&nbsp;&nbsp;action: file path='/etc/ssh/authorized\_keys' state=directory owner=root  
group=root mode=0755  
- name: add key for bob  
&nbsp;&nbsp;action: authorized\_key user=bob key='...snip...'  
sshdir='/etc/ssh/authorized\_keys' keysfile=bob  
- name: add key for john  
&nbsp;&nbsp;action: authorized\_key user=john key='...snip...'  
sshdir='/etc/ssh/authorized\_keys' keysfile=john

At which point I end up with an /etc/ssh/authorized\_keys directory set to  
0700 and owned by john. As long as the authorized\_key module makes  
permission changes then either a) it can't be used for this or b) it needs  
to be changed.

The whole point behind my thread was to discuss what would be considered  
the more appropriate change to the authorized\_key module to support this  
concept of alternate pathing for authorized\_keys. If the preference is to  
just consider authorized\_key a limited use case module and work around it,  
then so be it.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 9, 2013, 4:06am UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471/5 "2013-03-09T04:06:01Z")

</div>

> So... in the attached conversation I point out the flaw in utilizing an  
> external reference to the copy command. Effectively a bunch of extraneous  
> mode changing is/will be occurring.

I didn't suggest using the copy command.

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [March 9, 2013, 4:51am UTC](https://forum.ansible.com/t/extending-authorized-key-module/12471/6 "2013-03-09T04:51:38Z")

</div>

so we talked offline.

end result:

combine sshdir and keysfile parameters into path parameter and add  
manage\_dir boolean, defaulting to true.

This allows for alternate pathing of the key file, and manual setting of  
directory ownership in a separate task if the default ownership doesn't  
suit your environment.

-greg
