Deploy SSH Key to fabric switches
Change-Id: Iccf24cb48b1d7ed5c62873008876937ce7739ccf
diff --git a/roles/fabric-switch/tasks/main.yml b/roles/fabric-switch/tasks/main.yml
index 6bbb9df..41251e7 100644
--- a/roles/fabric-switch/tasks/main.yml
+++ b/roles/fabric-switch/tasks/main.yml
@@ -38,7 +38,7 @@
- reset
register: utils
-- name: Mark Persistent
+- name: Mark Utilities Persistent
command: persist {{ item }}
with_items:
- purge
@@ -47,7 +47,19 @@
- reset
when: utils.changed
+- name: Authorize SSH Key
+ become: yes
+ authorized_key:
+ key={{ pub_ssh_key }}
+ user=root
+ state=present
+ register: sshkey
+
+- name: Mark SSH Key Persistent
+ command: persist /root/.ssh/authorized_keys
+ when: sshkey.changed
+
- name: Persist
command: savepersist
- when: utils.changed
+ when: utils.changed or sshkey.changed
failed_when: false