Skip to content

authorized_key with regex #683

@KalleDK

Description

@KalleDK
SUMMARY

Add regex like lineinfile has it.
When we rotate the key we keep some of the comment the same, and it would be easy to rotate the key with a regex like lineinfil has it. Right now we either has to use lineinfile or remember all the old keys and make sure they are gone.

So in short replace the (first) line where the regex matches with the key OR add it to the end if none matches

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

authorized_key

ADDITIONAL INFORMATION
- name: Add authorized key to "ansible"
  ansible.posix.authorized_key:
    user: ansible
    state: present
    regex: "Bob @ Laptop"
    key: "ssh-ed25519 AAAAAxxxxxxxxxxx Bob @ Laptop 20251017"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions