blob: 9ac3e7830214cad734507f949146250f65da6774 [file] [log] [blame]
Sergio Slobodrianee4b2bc2017-06-05 10:08:59 -04001#!/bin/bash
2
3baseImage="Ubuntu1604LTS"
4iVmName="Ubuntu1604LTS-1"
5iVmNetwork="vagrant-libvirt"
6shutdownTimeout=5
7ipTimeout=10
8
9lBlue='\033[1;34m'
10green='\033[0;32m'
11orange='\033[0;33m'
12NC='\033[0m'
13red='\033[0;31m'
14yellow='\033[1;33m'
15dGrey='\033[1;30m'
16lGrey='\033[1;37m'
17lCyan='\033[1;36m'
18wd=`pwd`
19
20
21# Clean up any prior executions
22rm -fr .keys
23rm -f ansible/hosts/cluster
24rm -f ansible/host_vars/*
25
26# Source the configuration information
27. install.cfg
28
29# Create the key directory
30mkdir .keys
31
32# Create the host list
33echo "[cluster]" > ansible/hosts/cluster
34
35# Silence SSH and avoid prompts
36rm -f ~/.ssh/config
37echo "Host *" > ~/.ssh/config
38echo " StrictHostKeyChecking no" >> ~/.ssh/config
39echo " UserKnownHostsFile /dev/null" >> ~/.ssh/config
40
41sudo cp ~/.ssh/config /root/.ssh/config
42
43
44for i in $hosts
45do
46 # Generate the key for the host
47 echo -e "${lBlue}Generating the key-pair for communication with host ${yellow}$i${NC}"
48 ssh-keygen -f ./$i -t rsa -N ''
49 mv $i .keys
50
51 # Generate the pre-configuration script
52 echo -e "${lBlue}Creating the pre-configuration script${NC}"
53 cat <<HERE > bash_login.sh
54#!/bin/bash
55 echo "voltha ALL=(ALL) NOPASSWD:ALL" > tmp
56 sudo chown root.root tmp
57 sudo mv tmp /etc/sudoers.d/voltha
58 sudo mkdir /home/voltha
59 mkdir voltha_ssh
60 ssh-keygen -f ~/voltha_ssh/id_rsa -t rsa -N ''
61 sudo mv voltha_ssh /home/voltha/.ssh
62HERE
63 echo "sudo cat <<HERE > /home/voltha/.ssh/authorized_keys" >> bash_login.sh
64 cat $i.pub >> bash_login.sh
65 echo "HERE" >> bash_login.sh
66 echo "chmod 400 /home/voltha/.ssh/authorized_keys" >> bash_login.sh
67 echo "sudo useradd -b /home -d /home/voltha voltha -s /bin/bash" >> bash_login.sh
68 echo "sudo chown -R voltha.voltha /home/voltha" >> bash_login.sh
69 echo "echo 'voltha:voltha' | sudo chpasswd" >> bash_login.sh
70 echo "rm .bash_login" >> bash_login.sh
71 echo "logout" >> bash_login.sh
72 rm $i.pub
73 # Copy the pre-config file to the VM
74 echo -e "${lBlue}Transfering pre-configuration script to ${yellow}$i${NC}"
75 if [ -d ".test" ]; then
76 echo -e "${red}Test mode set!!${lBlue} Using pre-populated ssh key for ${yellow}$i${NC}"
77 scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i .test/$i bash_login.sh vagrant@$i:.bash_login
78 else
79 scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no bash_login.sh vagrant@$i:.bash_login
80 fi
81 rm bash_login.sh
82
83 # Run the pre-config file on the VM
84 echo -e "${lBlue}Running the pre-configuration script on ${yellow}$i${NC}"
85 if [ -d ".test" ]; then
86 echo -e "${red}Test mode set!!${lBlue} Using pre-populated ssh key for ${yellow}$i${NC}"
87 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i .test/$i vagrant@$i
88 else
89 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no vagrant@$i
90 fi
91
92 # Configure ansible and ssh for silent operation
93 echo -e "${lBlue}Configuring ansible${NC}"
94 echo $i >> ansible/hosts/cluster
95 echo "ansible_ssh_private_key_file: $wd/.keys/$i" > ansible/host_vars/$i
96
97 # Create the tunnel to the registry to allow pulls from localhost
98 echo -e "${lBlue}Creating a secure shell tunnel to the registry for ${yellow}$i${NC}"
99 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i .keys/$i -f voltha@$i -R 5000:localhost:5000 -N
100
101done
102# Add the dependent software list to the cluster variables
103echo -e "${lBlue}Setting up dependent software${NC}"
104echo "deb_files:" >> ansible/group_vars/all
105for i in deb_files/*.deb
106do
107echo " - `basename $i`" >> ansible/group_vars/all
108done
109
110# Running ansible
111echo -e "${lBlue}Running ansible${NC}"
112cp ansible/ansible.cfg .ansible.cfg
113sudo ansible-playbook ansible/voltha.yml -i ansible/hosts/cluster
114