Add/remove pub key with

gothsome
Wed, 20 Mar 2024 10:40:05 +0000
Get Help

Hello!
Im testing to use files with multiple keys in the.keys file.
My playbook successfully copies the keys, but in a single line.
Is it possible to use comments so you could see which key belongs to whom.
Playbook:

---
- name: Set authorized keys from gitlab
  hosts: all
  gather_facts: false
  vars:
    key_url: "http://192.168.151.237/awx/playbooks_pub/-/raw/main/ssh/granted_keys/granted.keys"
    key_content: "{{ lookup('url', key_url, split_lines=true) }}"

  tasks:
    - name: Set authorized keys taken from url
      ansible.posix.authorized_key:
        user: root
        state: present
        key: "{{ key_content }}"
        path: /root/.ssh/authorized_keys

The key are one in each line like you would do in a authorized_keys file.

Thank you very much again!

12 posts - 2 participants

Read full topic