-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow multiple authorized keys
- Loading branch information
1 parent
a2aa3b1
commit deb26b0
Showing
8 changed files
with
108 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
collections: | ||
- ansible.posix | ||
- community.general | ||
|
||
dependencies: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
--- | ||
collections: | ||
- ansible.posix | ||
- community.general |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
--- | ||
- name: Manage authorized key for {{ item.name }} | ||
- name: Ensure {{ item.name }}'s '.ssh' directory exists | ||
ansible.builtin.file: | ||
state: directory | ||
path: "{{ item.absolute_home_path }}/.ssh" | ||
mode: "0700" | ||
owner: "{{ item.name }}" | ||
group: "{{ item.primary_group if item.primary_group is defined and item.primary_group else item.name }}" | ||
|
||
- name: Manage authorized key(s) for {{ item.name }} | ||
when: | ||
- item.state == "present" | ||
- item.ssh_public_key is defined | ||
ansible.posix.authorized_key: | ||
exclusive: true | ||
key: "{{ item.ssh_public_key | default('') }}" | ||
key_options: |- | ||
{%- set from_options_global = user_management_default_ssh_from -%} | ||
{%- set from_options_custom_host = host_vars_ssh_from | default([]) -%} | ||
{%- set from_options_custom_item = item.custom_ssh_from | default([]) -%} | ||
{%- set from_options_custom = from_options_custom_host + from_options_custom_item | default([]) -%} | ||
{%- set from_options = from_options_global + from_options_custom | default([]) -%} | ||
from="{% if from_options %}{{ from_options | join(',') }}{% else %}*{% endif %}" | ||
state: present | ||
user: "{{ item.name }}" | ||
- item.ssh_public_keys is defined | ||
ansible.builtin.template: | ||
src: authorized_keys.j2 | ||
dest: "{{ item.absolute_home_path }}/.ssh/authorized_keys" | ||
mode: "0600" | ||
owner: "{{ item.name }}" | ||
group: "{{ item.primary_group if item.primary_group is defined and item.primary_group else item.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{%- for ssh_key in item.ssh_public_keys -%} | ||
{%- set from_options_global = user_management_default_ssh_from -%} | ||
{%- set from_options_custom_host = host_vars_ssh_from | default([]) -%} | ||
{%- set from_options_custom_item = item.custom_ssh_from | default([]) -%} | ||
{%- set from_options_custom = from_options_custom_host + from_options_custom_item | default([]) -%} | ||
{%- set from_options = from_options_global + from_options_custom | default([]) -%} | ||
{%- if ssh_key is defined -%} | ||
from="{% if from_options %}{{ from_options | join(',') }}{% else %}*{% endif %}" {{ ssh_key }} | ||
{% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters