# ssh management ansible

**URL:** <https://forum.ansible.com/t/ssh-management-ansible/35912>\
**Category:** Ansible Project\
**Created:** [October 22, 2021, 10:49pm UTC](https://forum.ansible.com/t/ssh-management-ansible/35912 "2021-10-22T22:49:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ndricim\_Danaj](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@Ndricim\_Danaj](https://forum.ansible.com/u/Ndricim_Danaj)\
**Post date:** [October 22, 2021, 10:49pm UTC](https://forum.ansible.com/t/ssh-management-ansible/35912/1 "2021-10-22T22:49:02Z")

</div>

TASK [Set up multiple authorized ssh] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [web1]: FAILED! =\> {“msg”: "The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to be in ‘/home/ndricim/playbooks/00.yml’: line 5, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [October 22, 2021, 10:51pm UTC](https://forum.ansible.com/t/ssh-management-ansible/35912/2 "2021-10-22T22:51:16Z")

</div>

Hi,

“with\_key:” should actually be “with\_items”

Alex

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 23, 2021, 6:02am UTC](https://forum.ansible.com/t/ssh-management-ansible/35912/3 "2021-10-23T06:02:52Z")

</div>

> TASK [Set up multiple authorized ssh] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [web1]: FAILED! =\> {“msg”: "The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to be in ‘/home/ndricim/playbooks/00.yml’: line 5, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n
> 
> * * *
> 
> - name: Set SSH Key  
> hosts: web1  
> tasks:
> - name: Set up multiple authorized ssh  
> authorized\_key:  
> user: work  
> state: present  
> key: ‘{{ item }}’  
> with\_key:
> - /home/ndricim/test/id\_rsa2.pub
> - /home/ndricim/test/id\_rsa3.pub

The keys are expected to be strings, not paths.  
Use lookup for that. See  
[https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized\_key\_module.html#examples](https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples)

---

<div class="post-metadata">

**Author:** ![steve\_missoh](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@steve\_missoh](https://forum.ansible.com/u/steve_missoh)\
**Post date:** [October 26, 2021, 12:31am UTC](https://forum.ansible.com/t/ssh-management-ansible/35912/4 "2021-10-26T00:31:42Z")

</div>

yeah …but he wants multiple keys to be shipped at once.  
so the solution is to keep everything as it is and replace **with\_key** with **with\_file**

Regards.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 26, 2021, 8:00am UTC](https://forum.ansible.com/t/ssh-management-ansible/35912/5 "2021-10-26T08:00:00Z")

</div>

And make sure with\_file is indented correctly.  
As shown on [https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized\_key\_module.html#examples](https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples)
