-
Notifications
You must be signed in to change notification settings - Fork 15
/
maas.yml
92 lines (91 loc) · 3.42 KB
/
maas.yml
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
write_files:
- content: |
config:
core.https_address: '[::]:8443'
core.trust_password: password
networks:
- config:
ipv4.address: 10.10.10.1/24
ipv6.address: none
description: ""
name: lxdbr0
type: ""
project: default
storage_pools:
- config:
size: 24GB
description: ""
name: default
driver: zfs
profiles:
- config: {}
description: ""
devices:
eth0:
name: eth0
network: lxdbr0
type: nic
root:
path: /
pool: default
type: disk
name: default
projects: []
cluster: null
path: /tmp/lxd.cfg
packages:
jq
snap:
commands:
- snap install maas
# - snap install --channel=3.0/stable maas
# - snap install --channel=latest/stable lxd
# - snap refresh --channel=latest/stable lxd
- snap install --channel=5.0/stable lxd
- snap refresh --channel=5.0/stable lxd
- snap install maas-test-db
- snap install maas-test-db
runcmd:
# Fetch IPv4 address from the device, setup forwarding and NAT
- export IP_ADDRESS=$(ip -j route show default | jq -r '.[].prefsrc')
- export INTERFACE=$(ip -j route show default | jq -r '.[].dev')
- sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
- sysctl -p
- iptables -t nat -A POSTROUTING -o $INTERFACE -j SNAT --to $IP_ADDRESS
# Persist NAT configuration
- echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
- echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
- apt-get install iptables-persistent -y
# LXD init
- cat /tmp/lxd.cfg | lxd init --preseed
# Wait for LXD to be ready
- lxd waitready
# Initialise MAAS
- maas init region+rack --database-uri maas-test-db:/// --maas-url http://${IP_ADDRESS}:5240/MAAS
- sleep 15
# Create MAAS admin and grab API key
- maas createadmin --username admin --password admin --email admin
- export APIKEY=$(maas apikey --username admin)
# MAAS admin login
- maas login admin 'http://localhost:5240/MAAS/' $APIKEY
# Configure MAAS networking (set gateways, vlans, DHCP on etc)
- export SUBNET=10.10.10.0/24
- export FABRIC_ID=$(maas admin subnet read "$SUBNET" | jq -r ".vlan.fabric_id")
- export VLAN_TAG=$(maas admin subnet read "$SUBNET" | jq -r ".vlan.vid")
- export PRIMARY_RACK=$(maas admin rack-controllers read | jq -r ".[] | .system_id")
- maas admin subnet update $SUBNET gateway_ip=10.10.10.1
- maas admin ipranges create type=dynamic start_ip=10.10.10.200 end_ip=10.10.10.254
- maas admin vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK
- maas admin maas set-config name=upstream_dns value=8.8.8.8
# Add LXD as a VM host for MAAS
- maas admin vm-hosts create password=password type=lxd power_address=https://${IP_ADDRESS}:8443 project=maas
# Automatically create and add ssh keys to MAAS
- ssh-keygen -q -t rsa -N "" -f "/home/ubuntu/.ssh/id_rsa"
- chown ubuntu:ubuntu /home/ubuntu/.ssh/id_rsa /home/ubuntu/.ssh/id_rsa.pub
- chmod 600 /home/ubuntu/.ssh/id_rsa
- chmod 644 /home/ubuntu/.ssh/id_rsa.pub
- maas admin sshkeys create key="$(cat /home/ubuntu/.ssh/id_rsa.pub)"
# Wait for images to be synced to MAAS
#- echo "Waiting for images to be synced to MAAS ..."
#- export status="downloading"
#- while [ "$status" != "synced" ]; do export status=$(maas admin rack-controller list-boot-images $PRIMARY_RACK | jq -r .status); sleep 1; done