Add ssh users with ansible roles 79/23079/1
authorYujun Zhang <zhang.yujunz@zte.com.cn>
Thu, 13 Oct 2016 07:58:10 +0000 (15:58 +0800)
committerYujun Zhang <zhang.yujunz@zte.com.cn>
Thu, 13 Oct 2016 07:58:10 +0000 (15:58 +0800)
Change-Id: I10a9f1ed2fbc1fbef5d488263b25d482fcaa320b
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
supporting/servers/roles/ssh/defaults/main.yml [new file with mode: 0644]
supporting/servers/roles/ssh/files/taseer.authorized_keys [new file with mode: 0644]
supporting/servers/roles/ssh/files/yujunz.authorized_keys [new file with mode: 0644]
supporting/servers/roles/ssh/tasks/main.yml [new file with mode: 0644]
supporting/servers/ssh.yml [new file with mode: 0644]

diff --git a/supporting/servers/roles/ssh/defaults/main.yml b/supporting/servers/roles/ssh/defaults/main.yml
new file mode 100644 (file)
index 0000000..ed3fbe6
--- /dev/null
@@ -0,0 +1,4 @@
+---
+users:
+  - { name: yujunz, comment: "Yujun Zhang <zhang.yujunz@zte.com.cn>" }
+  - { name: taseer, comment: "Taseer Ahmed <taseer94@gmail.com>" }
diff --git a/supporting/servers/roles/ssh/files/taseer.authorized_keys b/supporting/servers/roles/ssh/files/taseer.authorized_keys
new file mode 100644 (file)
index 0000000..2efb95e
--- /dev/null
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCxCG9Z+8rBLQiJ9yt+RzRkAZZQIlou83e899Kkuf/UgXd+1TUgIu4AJUDvayrorTxk2kw7ra+DoysEa2NBkLL6FNnG+NpYV+XTaG+Z3tvp4l62ROV+5+O4soiWtBroRghQPDkrpiTQuFJ7/BKQt9bKZYPb3t2bxCLeFVWtUzCpFDIj6wDPGwDeTLnLMPtQNQtIlgPV+XGAet17rNSrm7EcDzqdDQcdZFmfeH5YvBsY9ZO+qwcbelEpMBWPsyEMU6OgwTqUj7mm3o+Quew35y13Zrhf+GAx5ZMXho/Cpjp1TzognDkwAFpFzZG7zWSNexXrD15Wzgyae2cl/vD75I7 taseer@123.org
\ No newline at end of file
diff --git a/supporting/servers/roles/ssh/files/yujunz.authorized_keys b/supporting/servers/roles/ssh/files/yujunz.authorized_keys
new file mode 100644 (file)
index 0000000..168979c
--- /dev/null
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0o+WARhbI5DeZK9eiZKVprY3oQ910npo/EPFI9prfpN7zeF0UA4TwT9rqsrwFgRQeJkKvbDTOPt5Ox9vLIEnxT4PdirvrYNxtyJHHfbL4ZxKemYhBi2BA6CAbI3f9CR+dtbfOBxtTpXAj1Y5oA9y59o1hqHpuVmM8dBpcQt/ELdYCHZ0khxft5WaSOURsslTZN18bikVX9WHlKflVyRA8efxqzTZ4w5ufHl1Fv9i/G0u7iGbUtvlI8X7+Z+ePuysZhHKErQSGfv2NybDi+r8xM5hL2LYXxjAu0PV58olUl1SX40OY9yA2Yx+PVzIGhv6EQ8snUFnsoMy0ZIbQ+ysB yujunz@silver.mbp
diff --git a/supporting/servers/roles/ssh/tasks/main.yml b/supporting/servers/roles/ssh/tasks/main.yml
new file mode 100644 (file)
index 0000000..7de1e20
--- /dev/null
@@ -0,0 +1,26 @@
+- name: add users for ssh access
+  become: true
+  user:
+    name: "{{ item.name }}"
+    comment: "{{ item.comment }}"
+    groups: "qtip"
+    append: yes
+  with_items: "{{ users }}"
+- name: create .ssh directory
+  become: true
+  file:
+    path: "/home/{{ item.name }}/.ssh"
+    state: directory
+    owner: "{{ item.name }}"
+    group: "{{ item.name }}"
+    mode: 0700
+  with_items: "{{ users }}"
+- name: authorize public key
+  become: true
+  copy:
+    src: "{{ item.name }}.authorized_keys"
+    dest: "/home/{{ item.name }}/.ssh/authorized_keys"
+    owner: "{{ item.name }}"
+    group: "{{ item.name }}"
+    mode: 0600
+  with_items: "{{ users }}"
\ No newline at end of file
diff --git a/supporting/servers/ssh.yml b/supporting/servers/ssh.yml
new file mode 100644 (file)
index 0000000..bd74ab3
--- /dev/null
@@ -0,0 +1,4 @@
+---
+- hosts: elk-servers
+  roles:
+    - ssh