forked from UoW-CPC/jqueuer-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloud_init_worker.yaml
108 lines (96 loc) · 4.43 KB
/
cloud_init_worker.yaml
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
100
101
102
103
104
105
106
107
108
#cloud-config
apt_upgrade: false
apt_update: false
manage_etc_hosts: false
package_update: false
package_upgrade: false
write_files:
- content: |
{
"server": false,
"datacenter": "application",
"data_dir": "/var/consul",
"encrypt": "uohStneoKEoVYZIASGp6Nw==",
"log_level": "INFO",
"enable_syslog": false,
"retry_join": ["{{variables.master_host_ip}}"],
"rejoin_after_leave": true,
"services": [{"name":"worker_cluster","port":9100}, {"name":"app_docker_cluster","port":9200}]
}
path: /etc/consul/config.json
# set hostname
#- content: |
# #!/bin/sh
# if [ $reason = "BOUND" ]; then
# oldhostname=$(hostname -s)
# if [ $oldhostname != $new_host_name ]; then
# # Rename Host
# echo $new_host_name > /etc/hostname
# hostname -F /etc/hostname
# # Update /etc/hosts if needed
# TMPHOSTS=/etc/hosts.dhcp.new
# if ! grep "$new_ip_address $new_host_name.$new_domain_name $new_host_name" /etc/hosts; then
# # Remove the 127.0.1.1 put there by the debian installer
# grep -v '127\.0\.1\.1 ' < /etc/hosts > $TMPHOSTS
# # Add the our new ip address and name
# echo "$new_ip_address $new_host_name.$new_domain_name $new_host_name" >> $TMPHOSTS
# mv $TMPHOSTS /etc/hosts
# fi
# # Recreate SSH2 keys
# export DEBIAN_FRONTEND=noninteractive
# dpkg-reconfigure openssh-server
# fi
# fi
# path: /etc/dhcp/dhclient-exit-hooks.d/sethostname
# set hostname
- content: |
#!/bin/bash
echo "Setup NETWORK starts."
myhost=`hostname`
ipaddress=`ifconfig | awk '/inet addr/{print substr($2,6)}' | grep -v 127.0.0.1 | head -n 1`
cp /etc/hosts /etc/hosts.old
grep -v "$myhost" /etc/hosts.old > /etc/hosts
echo "IPADDRESS: $ipaddress"
echo "$ipaddress $myhost" >> /etc/hosts
rm -rf /etc/resolvconf/*
echo "Setup NETWORK finished."
path: /bin/consul-set-network.sh
permissions: '755'
- path: /etc/resolvconf/resolv.conf.d/base
content: |
nameserver 8.8.8.8
runcmd:
- adduser --disabled-password --gecos "" prometheus
- /bin/consul-set-network.sh
#- sudo hostnamectl set-hostname $(date +%s | sha256sum | base64 | head -c 32 ; echo)
# host: ubuntu
- sudo dhclient
- oldhostname=$(hostname -s)
- new_host_name=worker-$(date +%s | sha256sum | base64 | head -c 32 ; echo)
- echo $new_host_name > /etc/hostname
- hostname -F /etc/hostname
- line=127.0.1.1'\t'$new_host_name
- sed -i "s/$oldhostname/$new_host_name/g" /etc/hosts
- echo $line >> /etc/hosts
- export DEBIAN_FRONTEND=noninteractive
- dpkg-reconfigure openssh-server
- resolvconf -u
- echo nameserver 8.8.8.8 >> /etc/resolv.conf
# Docker
- apt-get update
- apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl software-properties-common wget unzip
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update
- apt-get install -y docker-ce=17.09.1~ce-0~ubuntu
- systemctl enable docker
# Connect to Swarm
- wget --retry-connrefused -qO /tmp/swarm_join {{variables.master_host_ip}}:2375/v1.26/swarm
- export TOKEN=$(grep -Eo 'SWMTKN-[[:alnum:]]*-[[:alnum:]]*-[[:alnum:]]*' /tmp/swarm_join | head -1)
- docker swarm join --token $TOKEN {{variables.master_host_ip}}:2377
# Infra services start
- export IP=$(hostname -I | cut -d\ -f1)
- sudo docker run -d --net=host -e 'CONSUL_LOCAL_CONFIG={"leave_on_terminate":true}' -p 8301:8301 -p 8301:8301/udp -p 8300:8300 -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600/udp -v /etc/consul/:/etc/consul consul:1.0.0 agent -advertise=$IP -retry-join={{variables.master_host_ip}} -config-file=/etc/consul/config.json
- sudo docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=9200:8080 --detach=true --name=cadvisor google/cadvisor:v0.28.3
- sudo docker run -d -e "NODE_ID=$(hostname)" --net=jqueuer_network --name jqueuer_agent_$IP -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker --log-driver syslog --log-opt syslog-address=udp://{{variables.master_host_ip}}:5514 --log-opt tag=$(hostname) jaydes/jqueuer_agent
- sudo docker run -d -p 9100:9100 prom/node-exporter:v0.15.2