summaryrefslogtreecommitdiff
path: root/ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml
diff options
context:
space:
mode:
authorboom2 <blizzack@blizzack.com>2023-12-21 15:49:16 -0500
committerboom2 <blizzack@blizzack.com>2023-12-21 15:49:16 -0500
commit200680e7c8cbd6b4426c3ce232568b1e06446bde (patch)
treeb122f103cc4dce8cea078c20dac107612399640e /ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml
parenta21b2f4bb64bd0f633d8a6a15f27a73103df70c0 (diff)
- renamed playbook to follow convention
-- add /etc/rc.d/rc.M in 'fetch file playbook' for future clamav playbook
Diffstat (limited to 'ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml')
-rw-r--r--ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml29
1 files changed, 29 insertions, 0 deletions
diff --git a/ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml b/ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml
new file mode 100644
index 0000000..c046fe9
--- /dev/null
+++ b/ansible-practice/system/13_2-playbook-create-update-user-authorized_key.yml
@@ -0,0 +1,29 @@
+#
+# https://www.codesandnotes.be/2020/01/13/generate-ssh-keys-using-ansible/
+# https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html
+# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_lookups.html
+#
+# - i couldnt really understand why we would use this module 'after' we created the
+# 'testuser' w/ an ssh key.
+#
+# tldr; you don't !!!!
+#
+# - the correct way to use this is if u have a list of users and their public keys
+# stored on the controller node. then when you create a managed node
+# you can loop thru creating new users on it and add their public keys to that
+# new node in a playbook.
+#
+---
+- name: "13.2 -- custom ansible - create/update user with a prompt"
+ hosts: dev
+ become: yes # Run tasks with root/sudo privileges
+ vars:
+ username: testuser1
+ ssh_path: "keys/{{ username }}/id_ed25519.pub"
+
+ tasks:
+ - name: set authorized key taken from file
+ ansible.posix.authorized_key:
+ user: "{{ username }}"
+ state: present # ensure the user is present
+ key: "{{ lookup('file', ssh_path) }}"