-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeployLXCdevContainers.sh
More file actions
executable file
·99 lines (81 loc) · 2.83 KB
/
deployLXCdevContainers.sh
File metadata and controls
executable file
·99 lines (81 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
lxcExist=`command -v lxc`
sshKey=`cat ~/.ssh/id_rsa.pub`
poil1Name="master"
poil2Name="worker0"
if ! [ -x "$lxcExist" ]
then
echo ------------------------------------
echo "You must install and init lxd before using this script"
echo "See this official wiki : https://linuxcontainers.org/fr/lxd/getting-started-cli/"
echo ------------------------------------
exit 1
fi
if [ -z "$sshKey" ]
then
echo ------------------------------------
echo "You must generate an ssh key before using this script"
echo "you can execute : ssh-keygen"
echo ------------------------------------
exit 1
fi
echo ------------------------------------
echo "Creating lxc container"
lxc launch ubuntu:16.04 $poil1Name
lxc launch ubuntu:16.04 $poil2Name
echo Done
echo ------------------------------------
echo "Wait for container to start"
ipPoil1=`lxc info $poil1Name | grep -P "eth0:\tinet\t" | awk '{print $3}'`
ipPoil2=`lxc info $poil2Name | grep -P "eth0:\tinet\t" | awk '{print $3}'`
while [ -z $ipPoil1 ] || [ -z $ipPoil2 ]
do
ipPoil1=`lxc info $poil1Name | grep -P "eth0:\tinet\t" | awk '{print $3}'`
ipPoil2=`lxc info $poil2Name | grep -P "eth0:\tinet\t" | awk '{print $3}'`
done
echo Done
echo -----------------------------------
echo "Removing existing public key in ssh known_hosts"
ssh-keygen -f ~/.ssh/known_hosts -R $ipPoil1
ssh-keygen -f ~/.ssh/known_hosts -R $ipPoil2
echo Done
echo ------------------------------------
echo "Installing python on lxc container"
lxc exec $poil1Name -- apt-get update -y
lxc exec $poil2Name -- apt-get update -y
lxc exec $poil1Name -- apt-get install python -y
lxc exec $poil2Name -- apt-get install python -y
echo Done
echo ------------------------------------
echo "Setup ssh key"
lxc exec $poil1Name -- bash -c "echo $sshKey > /root/.ssh/authorized_keys"
lxc exec $poil2Name -- bash -c "echo $sshKey > ~/.ssh/authorized_keys"
echo Done
echo ------------------------------------
echo "Add container to ssh know host"
ssh root@$ipPoil1 -o StrictHostKeyChecking=no exit
ssh root@$ipPoil2 -o StrictHostKeyChecking=no exit
echo Done
echo ------------------------------------
echo "Add opv_master line in /etc/host"
lineOpvMaster=`cat /etc/hosts | grep opv_master -n | awk '{print $1}' FS=":"`
for i in $lineOpvMaster
do
sudo sed -i "${i}s/.*/#&/" /etc/hosts
done
echo $ipPoil1 opv_master | sudo tee -a /etc/hosts
echo Done
echo ------------------------------------
echo "Make hosts file of ansible"
cat /dev/null > hosts
echo "[Master]" >> hosts
echo "$poil1Name ansible_host=$ipPoil1" >> hosts
echo "" >> hosts
echo "[Worker]" >> hosts
echo "$poil2Name ansible_host=$ipPoil2" >> hosts
echo Done
echo ------------------------------------
echo "Finish !"
echo "You are now ready to use this container with ansible"
echo "Ip of $poil1Name : $ipPoil1 Ip of $poil2Name : $ipPoil2"
echo ------------------------------------