# Error reporting for authorized\_key module

**URL:** <https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009>\
**Category:** Ansible Project\
**Created:** [April 13, 2014, 7:36pm UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009 "2014-04-13T19:36:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francisco\_Reyes](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Francisco\_Reyes](https://forum.ansible.com/u/Francisco_Reyes)\
**Post date:** [April 13, 2014, 7:36pm UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009/1 "2014-04-13T19:36:27Z")

</div>

If the key file to read is not found, shouldn’t the authorized\_key module report an error?

Have this in a playbook

- name: Manage keys for users  
authorized\_key: user={{item.uname}} key=“{{lookup(‘file’,‘~/Ansible/keys/’ + item.uname + ‘/authorized\_keys2’) }}”  
manage\_dir=yes  
path=‘/home/{{item.uname}}/.ssh/authorized\_keys2’  
with\_items: Ops

I originally had the folder “Ansible” called something else. Upon rename keys stopped getting installed, but the module did not report an error.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 15, 2014, 9:15pm UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009/2 "2014-04-15T21:15:43Z")

</div>

If the lookup file is not found, it _should_ produce an exception, yes.

If you are seeing this behavior on the development branch, please make sure there is a ticket on github.

(To be clear, this has nothing to do with the authorized key module in the end, and everything to do with the lookup plugin)

Thanks!

---

<div class="post-metadata">

**Author:** ![Francisco\_Reyes](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Francisco\_Reyes](https://forum.ansible.com/u/Francisco_Reyes)\
**Post date:** [April 19, 2014, 4:28pm UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009/3 "2014-04-19T16:28:37Z")

</div>

> If the lookup file is not found, it _should_ produce an exception, yes.  
> If you are seeing this behavior on the development branch, please make sure there is a ticket on github.

ansible 1.6 (devel ae29e43f93) last updated 2014/04/19 14:46:18 (GMT +000)  
Still has the issue

> (To be clear, this has nothing to do with the authorized key module in the end, and everything to do with the lookup plugin)

Looking at the documentation at [http://docs.ansible.com/authorized\_key\_module.html](http://docs.ansible.com/authorized_key_module.html) there is also an option to use

```auto
# Using with_file
- name: Set up authorized_keys for the deploy user
  authorized_key: user=deploy
                  key="{{ item }}"
  with_file:
    - public_keys/doe-jane
    - public_keys/doe-john

```

```auto
So in that case if the key file is not found, shouldn't it also produce an error?

```

```auto
Doesn't that mean that authorized_key itself should check that it has a file and not only the lookup plugin?

```

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [April 20, 2014, 12:51am UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009/4 "2014-04-20T00:51:59Z")

</div>

the module actually does not work with files, it takes a string (key) as an input, the file lookup module lets you get those strings from files.​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 16, 2014, 7:51pm UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009/5 "2014-09-16T19:51:41Z")

</div>

Yes.

This mayb ethe lookup plugin you have here evaluating lazily and then the authorized key module inserting the lookup call into the file.  
Obviously we don’t want that, but there are reasons the lookup plugin itself doesn’t error - but we should catch that later.

Before going further, can you share what version of ansible you are using?

If 1.7.X or 1.8 (devel), please go ahead and file a bug on this.

Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 16, 2014, 7:52pm UTC](https://forum.ansible.com/t/error-reporting-for-authorized-key-module/15009/6 "2014-09-16T19:52:40Z")

</div>

Sorry, ignore that last one.

I was in our legacy email account from before the company name change and going through the wrong mail folder 🙂
