Browse Source

Merge "Add ssh public key to Fuel master node"

Jenkins 2 years ago
parent
commit
46f785a489
3 changed files with 37 additions and 0 deletions
  1. 6
    0
      actions/master-node-create-and-install.sh
  2. 3
    0
      config.sh
  3. 28
    0
      functions/product.sh

+ 6
- 0
actions/master-node-create-and-install.sh View File

@@ -72,6 +72,12 @@ enable_outbound_network_for_product_vm $vm_master_ip $vm_master_username $vm_mas
72 72
 # Wait until the machine gets installed and Puppet completes its run
73 73
 wait_for_product_vm_to_install $vm_master_ip $vm_master_username $vm_master_password "$vm_master_prompt"
74 74
 
75
+#Add public key to authorized_keys
76
+if [ -e "${public_key_file}" ]; then
77
+  public_key=$(cat "${public_key_file}")
78
+  update_authorized_key $vm_master_ip $vm_master_username $vm_master_password "$vm_master_prompt" "$public_key"
79
+fi
80
+
75 81
 # Report success
76 82
 echo
77 83
 echo "Master node has been installed."

+ 3
- 0
config.sh View File

@@ -190,3 +190,6 @@ skipfuelmenu="yes"
190 190
 
191 191
 # default cmdline parameters passed to the kernel when boot the Fuel Master node
192 192
 cmdline="initrd=initrd.img net.ifnames=0 biosdevname=0 ks=hd:sr0:/ks.cfg ip=10.20.0.2::10.20.0.1:255.255.255.0:fuel.domain.tld:eth0:off::: dns1=10.20.0.1"
193
+
194
+# If necessary uncomment and edit line below to add your public ssh key to the master node
195
+#public_key_file="${HOME}/.ssh/id_rsa.pub"

+ 28
- 0
functions/product.sh View File

@@ -300,3 +300,31 @@ print_no_internet_connectivity_banner() {
300 300
     echo "#          because there is no Internet connectivity       #"
301 301
     echo "############################################################"
302 302
 }
303
+
304
+update_authorized_key() {
305
+    local ip=$1
306
+    local username=$2
307
+    local password=$3
308
+    local prompt=$4
309
+    local key=$5
310
+
311
+    echo -n "Adding public ssh key for '${username}' on '${ip}' node... "
312
+
313
+    result=$(
314
+        execute expect << ENDOFEXPECT
315
+        spawn ssh $ssh_options $username@$ip
316
+        expect "connect to host" exit
317
+        expect "*?assword:*"
318
+        send "$password\r"
319
+        expect "$prompt"
320
+        send "mkdir -p -m 0700 ~/.ssh\r"
321
+        expect "$prompt"
322
+        send "echo \"$key\" >>~/.ssh/authorized_keys\r"
323
+        expect "$prompt"
324
+        send "logout\r"
325
+        expect "$prompt"
326
+ENDOFEXPECT
327
+    )
328
+    echo "OK"
329
+    return 0
330
+}

Loading…
Cancel
Save