@@ -18,95 +18,46 @@ packages:
18
18
- mariadb-client
19
19
- php5-curl
20
20
- nfs-common
21
- - python-pip
22
- - python-dev
23
21
- curl
24
22
- jq
25
23
26
24
write_files :
27
25
- content : |
28
- #!/usr/bin/python
29
- import ovh
30
- from netifaces import interfaces, ifaddresses, AF_INET
31
- client = ovh.Client()
32
- params = {}
33
- params['address'] = ifaddresses('eth0').setdefault(AF_INET, [{'addr':'No IP addr'}] )[0]['addr']
34
- params['status'] = 'active'
35
- result = client.post('/ipLoadbalancing/--IPLB--/server', **params)
36
- params = {}
37
- params['serverId'] = result['id']
38
- params['probe'] = 'true'
39
- result = client.post('/ipLoadbalancing/--IPLB--/backend/--BACKEND--/server', **params)
40
- params = {}
41
- params['zone'] = 'gra'
42
- result = client.post('/ipLoadbalancing/--IPLB--/refresh', **params)
43
- path: /root/ovh-add-in-iplb.py
26
+ #!/bin/bash
27
+ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@--IPLB-- "echo ' server $(hostname) --MYIP--:80 maxconn 32' >> /etc/haproxy/haproxy.cfg; service haproxy restart"
28
+ path: /root/ovh-add-in-iplb
44
29
owner: root:root
45
30
permissions: '0755'
46
31
- content : |
47
- #!/usr/bin/python
48
- import ovh
49
- from netifaces import interfaces, ifaddresses, AF_INET
50
- client = ovh.Client()
51
- params = {}
52
- params['address'] = ifaddresses('eth0').setdefault(AF_INET, [{'addr':'No IP addr'}] )[0]['addr']
53
- result = client.get('/ipLoadbalancing/--IPLB--/server', **params)
54
- id = result[0]
55
- params = {}
56
- result = client.get('/ipLoadbalancing/--IPLB--/backend/--BACKEND--/server', **params)
57
- for i in result:
58
- params = {}
59
- result_to_delete = client.get('/ipLoadbalancing/--IPLB--/backend/--BACKEND--/server/' + str(i), **params)
60
- if result_to_delete['serverId'] == id:
61
- params = {}
62
- client.delete('/ipLoadbalancing/--IPLB--/backend/--BACKEND--/server/' + str(i), **params)
63
- client.delete('/ipLoadbalancing/--IPLB--/server/' + str(result_to_delete['serverId']), **params)
64
- params = {}
65
- params['zone'] = 'gra'
66
- result = client.post('/ipLoadbalancing/--IPLB--/refresh', **params)
67
- path: /root/ovh-del-in-iplb.py
32
+ #!/bin/bash
33
+ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@--IPLB-- "sed -i -re /$(hostname)/d /etc/haproxy/haproxy.cfg; service haproxy restart"
34
+ path: /root/ovh-del-in-iplb
68
35
owner: root:root
69
36
permissions: '0755'
70
37
- content : |
71
38
[Unit]
72
- Description=Subscribe to the IPLB at OVH with the local public IP on eth0
39
+ Description=Subscribe to the loadbalancer with the local public IP on eth0
73
40
Wants=cloud-init.service
74
41
75
42
[Service]
76
43
Type=oneshot
77
44
RemainAfterExit=yes
78
- ExecStart=/root/ovh-add-in-iplb.py
79
- ExecStop=/root/ovh-del-in-iplb.py
45
+ ExecStart=/root/ovh-add-in-iplb
46
+ ExecStop=/root/ovh-del-in-iplb
80
47
81
48
[Install]
82
49
WantedBy=multi-user.target
83
50
path: /etc/systemd/system/ovh-iplb-subscription.service
84
51
owner: root:root
85
52
permissions: '0644'
86
- - content : |
87
- #!/bin/bash
88
- cat > /etc/ovh.conf <<EOF
89
- [default]
90
- endpoint=ovh-eu
91
-
92
- [ovh-eu]
93
- EOF
94
- echo "application_key=$(curl -s http://169.254.169.254/openstack/latest/meta_data.json | jq .meta.application_key | sed s'/\"//g')" >> /etc/ovh.conf
95
- echo "application_secret=$(curl -s http://169.254.169.254/openstack/latest/meta_data.json | jq .meta.application_secret| sed s'/\"//g')" >> /etc/ovh.conf
96
- echo "consumer_key=$(curl -s http://169.254.169.254/openstack/latest/meta_data.json | jq .meta.consumer_key | sed s'/\"//g')" >> /etc/ovh.conf
97
- path: /root/ovh-api-confgen
98
- owner: root:root
99
- permissions: '0755'
100
53
101
54
runcmd :
102
- - pip install ovh
103
- - pip install netifaces
104
- - /root/ovh-api-confgen
105
55
- iplb=$(curl -s http://169.254.169.254/openstack/latest/meta_data.json | jq .meta.iplb | sed s'/\"//g')
106
- - iplbbackend =$(curl -s http://169.254.169.254/openstack/latest/meta_data.json | jq .meta.iplbbackend | sed s'/\"//g' )
107
- - sed -i -re "s/--IPLB--/$iplb/g" /root/ovh-del-in-iplb.py /root/ovh-add-in-iplb.py
108
- - sed -i -re "s/--BACKEND --/$iplbbackend /g" /root/ovh-del-in-iplb.py /root/ovh-add-in-iplb.py
56
+ - myip =$(curl ifconfig.me )
57
+ - sed -i -re "s/--IPLB--/$iplb/g" /root/ovh-del-in-iplb /root/ovh-add-in-iplb
58
+ - sed -i -re "s/--MYIP --/$myip /g" /root/ovh-del-in-iplb /root/ovh-add-in-iplb
109
59
- systemctl enable ovh-iplb-subscription.service
110
60
- systemctl start ovh-iplb-subscription.service
111
61
- service apache2 restart
112
62
- rm -f /var/www/html/index.html
63
+ - mount -a
0 commit comments