ssh management ansible

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

Hi,

“with_key:” should actually be “with_items”

Alex

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

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.

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