Default code to add public ssh key fails

I got it:

---
- name: Set authorized keys
  hosts: all
  gather_facts: false
  vars:
    key_url: "https://raw.githubusercontent.com/gsg-git/awx_pub/main/awxtestpub"
    key_content: "{{ lookup('url', key_url, split_lines=false) }}"
    conversion_cmd: 'ssh-keygen -i -m RFC4716 -f /dev/stdin <<<"{{ key_content }}"'
    new_key_content: "{{ lookup('pipe', conversion_cmd) }}"
    commentpath: '/root/.ssh/authorized_keys'
    commentcontent: '#Testkey'
  
  tasks:
    - name: addcomment
      lineinfile:
        path: "{{ commentpath }}"
        line: "{{ commentcontent }}"
    - name: Set authorized keys taken from url
      ansible.posix.authorized_key:
        user: root
        state: present
        key: "{{ new_key_content }}"
        path: /root/.ssh/authorized_keys

The function seems to know if the key i aleready added(?).
I thought it would just add the line, but at on test file it just added the comment after the aleready added key from yesterday.
Leaves the next task:
Reverse the funktion to remove the requested keys.
Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.