# authorized\_key : How to put default value or bypass it

**URL:** <https://forum.ansible.com/t/authorized-key-how-to-put-default-value-or-bypass-it/32036>\
**Category:** Ansible Project\
**Created:** [January 23, 2020, 8:24am UTC](https://forum.ansible.com/t/authorized-key-how-to-put-default-value-or-bypass-it/32036 "2020-01-23T08:24:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hieronymus1](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@Hieronymus1](https://forum.ansible.com/u/Hieronymus1)\
**Post date:** [January 23, 2020, 8:24am UTC](https://forum.ansible.com/t/authorized-key-how-to-put-default-value-or-bypass-it/32036/1 "2020-01-23T08:24:44Z")

</div>

Hi

I’m using the authorized\_key module in my ansible user role.  
As some user aren’t ssh key yet, I would like that by default this key is not created and the task escaped.  
I’ve seen that the key string is required by this module.  
Is means that I cannot put a false default value?

Here’s my main task:  
`  
[…]

- name: “add public keys to users”  
authorized\_key:  
user: ‘{{ item.name }}’  
key: ‘{{ item.ssh\_key }}’  
ignore\_errors: yes  
with\_items: ‘{{ user }}’  
[…]  
`

Here’s the definition yaml file:  
`  
[…]  
user:

- name: ‘bob’  
password: “{{ bob\_pass }}”  
comment: ‘Bob McKenzie’  
uid: ‘2000’  
group: ‘bob’  
groups: ‘wheel’  
shell: ‘/bin/bash’  
state: “{{ ‘present’ if bob\_pass else ‘absent’ }}”  
ssh\_key: “{{ bob\_key | default(false) }}”  
[…]  
`

The bob\_key is define in an another yaml variable file.

Here’s the error:  
`  
[WARNING]: The value False (type bool) in a string field was converted to ‘False’ (type string). If this does not look like what you expect, quote the entire value to ensure it does not change.

failed: [localhost] (item={‘name’: ‘tzdkom’, ‘password’: …  
… “msg”: “invalid key specified: False”}  
`

Is the variable ssh\_key: “{{ bob\_key | **default(false)** }}” wrong ?  
Could you please explain me this?  
Has someone an idea to bypass this problem when no ssh\_key exist?

Thanks and best regards,  
M.

---

<div class="post-metadata">

**Author:** ![Martin\_Krizek](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@Martin\_Krizek](https://forum.ansible.com/u/Martin_Krizek)\
**Post date:** [January 23, 2020, 11:12am UTC](https://forum.ansible.com/t/authorized-key-how-to-put-default-value-or-bypass-it/32036/2 "2020-01-23T11:12:53Z")

</div>

Just skip the item when ssh\_key is not available (`false` in your example):

- name: "add public keys to users"  
&nbsp;&nbsp;authorized\_key:  
&nbsp;&nbsp;&nbsp;&nbsp;user: '{{ item.name }}'  
&nbsp;&nbsp;&nbsp;&nbsp;key: '{{ item.ssh\_key }}'  
&nbsp;&nbsp;with\_items: '{{ user }}'  
&nbsp;&nbsp;when: item.ssh\_key

---

<div class="post-metadata">

**Author:** ![Hieronymus1](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@Hieronymus1](https://forum.ansible.com/u/Hieronymus1)\
**Post date:** [January 23, 2020, 12:40pm UTC](https://forum.ansible.com/t/authorized-key-how-to-put-default-value-or-bypass-it/32036/3 "2020-01-23T12:40:12Z")

</div>

That’s exactly what I need. I really hadn’t seen that.

Thanks a lot
