-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from abakanovskii/feature/add_path_option_aut…
…horized_key authorized_key: Allow local path to a key SUMMARY Add option to specify an absolute path to file with SSH key(s) for authorized_key ISSUE TYPE Feature Pull Request COMPONENT NAME authorized_key ADDITIONAL INFORMATION Before this change you would need to get key using ansible.builtin.slurp or something like ansible.builtin.command: cat <file> with register I tried to keep it as simple as possible # Now this is possible - name: Set authorized keys taken from path ansible.posix.authorized_key: user: charlie state: present key: /home/charlie/.ssh/id_rsa.pub Reviewed-by: Hideki Saito <[email protected]> Reviewed-by: alexander
- Loading branch information
Showing
5 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- authorized_keys - allow using absolute path to a file as a SSH key(s) source (https://github.com/ansible-collections/ansible.posix/pull/568) |
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
32 changes: 32 additions & 0 deletions
32
tests/integration/targets/authorized_key/tasks/check_path.yml
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,32 @@ | ||
--- | ||
- name: Create key file for test | ||
ansible.builtin.copy: | ||
dest: "{{ key_path }}" | ||
content: "{{ rsa_key_basic }}" | ||
mode: "0600" | ||
|
||
- name: Add key using path | ||
ansible.posix.authorized_key: | ||
user: root | ||
key: file://{{ key_path }} | ||
state: present | ||
path: "{{ output_dir | expanduser }}/authorized_keys" | ||
register: result | ||
|
||
- name: Assert that the key was added | ||
ansible.builtin.assert: | ||
that: | ||
- result.changed == true | ||
|
||
- name: Add key using path again | ||
ansible.posix.authorized_key: | ||
user: root | ||
key: file://{{ key_path }} | ||
state: present | ||
path: "{{ output_dir | expanduser }}/authorized_keys" | ||
register: result | ||
|
||
- name: Assert that no changes were applied | ||
ansible.builtin.assert: | ||
that: | ||
- result.changed == false |
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