-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_auto_le_do_droplet
44 lines (38 loc) · 1.2 KB
/
deploy_auto_le_do_droplet
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
require('droplet_kit')
mytoken='mysupersecrettoken'
thehostname=(0...50).map { (65 + rand(26)).chr }.join.downcase
domain='example.com'
myemail=''
$myip=''
sshkeys=Array.new
sshkeys[0]='00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00'
metadata="#!/bin/bash\napt-get update
apt-get -y install apache2 at
apt-get -y install python-letsencrypt-apache
/usr/bin/letsencrypt --agree-tos --apache -d "+thehostname+"."+domain+" --email '+myemail+' --non-interactive --redirect
ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key > /var/www/html/hostkey\necho '' > /var/www/html/index.html"
client = DropletKit::Client.new(access_token: mytoken)
droplet = DropletKit::Droplet.new(
name: thehostname+'.'+domain,
region: 'nyc3',
size: '512mb',
image: 'ubuntu-16-04-x64',
ipv6: true,
user_data: metadata,
ssh_keys:sshkeys
)
client.droplets.create(droplet)
sleep(10)
client.droplets.all().each { |test|
if test.name == thehostname+'.'+domain
$myip=test.networks.v4[0].ip_address
end
}
record = DropletKit::DomainRecord.new(
type: 'A',
name: thehostname,
data: $myip
)
client.domain_records.create(record, for_domain: domain)
puts "Created droplet #{thehostname} with IP:#{$myip}"
puts "https://#{thehostname}.#{domain}/"