Skip to content

Commit 0909c4d

Browse files
committed
Including DNS and DHCP tasks to the main role.
1 parent 959080c commit 0909c4d

16 files changed

+475
-98
lines changed

roles/maas/README.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Ansible Playbook: MAAS Installation and Configuration
2+
3+
This Ansible playbook automates the installation and initial configuration of [MAAS (Metal as a Service)](https://maas.io/) on Ubuntu-based systems.
4+
5+
## Features
6+
7+
- Installs MAAS packages
8+
- Initializes MAAS with a default user with HA
9+
- Configures networking (DHCP, DNS, etc.)
10+
- Adds Machines from invetory into MAAS
11+
12+
## Requirements
13+
14+
- Ansible 2.10+
15+
- Ubuntu 20.04 or later on the target system(s)
16+
- Sudo access on target host
17+
- Internet access (for downloading MAAS packages and images)
18+
- At least 2 Nodes to deploy MAAS with HA
19+
20+
## Inventory
21+
22+
Define your inventory in `hosts.ini` with the following structure:
23+
24+
```ini
25+
[maas_region_rack_server]
26+
test1 ip=172.x.x.x ipmi=10.0.8.x mac=08:00:27:ed:43:x
27+
28+
[maas_rack_server]
29+
test2 ip=172.x.x.x ipmi=10.0.8.x mac=08:00:27:ed:43:x
30+
31+
[maas_db_server]
32+
test1 ip=172.x.x.x ipmi=10.0.8.x mac=08:00:27:ed:43:x
33+
34+
The systems you want to add into MAAS should be on a group called [testnodes] with the same structure.
35+
36+
## Variables
37+
38+
You can configure the playbook via group_vars/maas.yml in the secret repo or defaults/main.yml. Common variables include:
39+
maas_admin_username: "admin"
40+
maas_admin_password: "adminpass"
41+
maas_admin_email: "admin@example.com"
42+
maas_admin_username: "admin"
43+
maas_db_name: "maasdb"
44+
maas_db_user: "maas"
45+
maas_version: "3.5"
46+
maas_snap_channel: "stable"
47+
48+
DNS variables include:
49+
dns_domains:
50+
- ceph: Static primary domain (e.g., `internal.ceph.tucson.com`).
51+
- ipmi: Static IPMI domain (`ipmi.ceph.tucson.com`).
52+
- vlan104: Static sub-domain for vlan104 address(`vlan104.internal.ceph.tucson.com`).
53+
default_domains: List of domains to preserve/ignore (default: `["maas"]`). The default domain is a DNS domain that is used by maas when you deploy a machine it is used by maas for internal dns records so we choose to exclude it from our ansible role.
54+
55+
DHCP variables include:
56+
dhcp_global_options:
57+
- ddns-update-style: none
58+
- default-lease-time: 43200
59+
- max-lease-time: 172800
60+
- one-lease-per-client: "true"
61+
62+
This list will be used to populate the global snippet. You can add additional keys and values. Just make sure they follow the syntax required for dhcpd.conf.
63+
64+
dhcp_maas_subnets:
65+
front:
66+
cidr: 10.0.8.0/24
67+
ipvar: ip
68+
macvar: mac
69+
start_ip: 10.0.8.10
70+
end_ip: 10.0.8.20
71+
ip_range_type: dynamic
72+
classes:
73+
virtual: "match if substring(hardware, 0, 4) = 01:52:54:00"
74+
lxc: "match if substring(hardware, 0, 4) = 01:52:54:ff"
75+
pools:
76+
virtual:
77+
range: 172.21.10.20 172.21.10.250
78+
unknown_clients:
79+
range:
80+
- 172.21.11.0 172.21.11.19
81+
- 172.21.13.170 172.21.13.250
82+
lxc:
83+
range: 172.21.14.1 172.21.14.200
84+
back:
85+
cidr: 172.21.16.0/20
86+
ipvar: back
87+
macvar: backmac
88+
89+
This is large dictionary that gets parsed out into individual snippet files. Each top-level key (front and back in the example) will get its own snippet file created. The example shown to the left is our actual dhcp_maas_subnets dictionary.
90+
91+
Under each subnet, cidr, ipvar, and macvar are required. ipvar and macvar tell the Jinja2 template which IP address and MAC address should be used for each host in each subnet snippet.
92+
93+
Here's a line from our Ansible inventory host file
94+
95+
smithi001.front.sepia.ceph.com mac=0C:C4:7A:BD:15:E8 ip=172.21.15.1 ipmi=172.21.47.1 bmc=0C:C4:7A:6E:21:A7
96+
97+
This will result in a static IP entry for smithi001-front with IP 172.21.15.1 and MAC 0C:C4:7A:BD:15:E8 in front_hosts snippet and a smithi001-ipmi entry with IP 172.21.47.1 with MAC 0C:C4:7A:6E:21:A7 in ipmi_hosts snippet.
98+
99+
## Usage
100+
101+
1. Clone the repository:
102+
103+
git clone https://github.com/ceph/ceph-cm-ansible.git
104+
cd ceph-cm-ansible
105+
106+
2. Update inventory and variables.
107+
108+
3. Run the playbook:
109+
110+
ansible-playbook -i hosts.ini maas.yml
111+
112+
## Role Structure
113+
114+
maas
115+
   ├── defaults
116+
   │   └── main.yml
117+
   ├── meta
118+
   │   └── main.yml
119+
   ├── tasks
120+
   │   ├── add_machines.yml
121+
   │   ├── config_dhcpd.yml
122+
   │   ├── config_dns.yml
123+
   │   ├── initialize_region_rack.yml
124+
   │   ├── initialize_secondary_rack.yml
125+
   │   ├── install_maasdb.yml
126+
   │   └── main.yml
127+
   └── templates
128+
   ├── dhcpd.classes.conf.j2
129+
   ├── dhcpd.global.conf.j2
130+
   ├── dhcpd.hosts.conf.j2
131+
   └── dhcpd.pools.conf.j2
132+
133+
## Tags
134+
135+
- install_maas #Install MAAS and postgreSQL only and initializes the region+rack server and the secondary rack.
136+
- add-machines #Add Machines to MAAS only if they are not already present.
137+
- config_dhcp #Configures DHCP options only if there are any change in the DHCP variables.
138+
- config_dns #Configure DNS domains and add the DNS Records that are not currenlty into a Domain.

roles/maas/defaults/main.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ maas_db_user: "maas"
66
maas_version: "3.5"
77
maas_snap_channel: "stable"
88

9+
# DNS Variables
10+
default_domains:
11+
- "maas"
12+

roles/maas/defaults/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
# MAAS user and database variables
3+
maas_admin_username: "admin"
4+
maas_db_name: "maasdb"
5+
maas_db_user: "maas"
6+
maas_version: "3.5"
7+
maas_snap_channel: "stable"
8+
9+
# DNS Variables
10+
dns_domains:
11+
ceph: "internal.ceph.ibm.com"
12+
ipmi: "ipmi.ceph.ibm.com"
13+
vlan104: "vlan104.internal.ceph.ibm.com"
14+
15+
default_domains:
16+
- "maas"
17+

roles/maas/meta/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
dependencies:
3+
- role: secrets

roles/maas/tasks/add_machines.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22
- name: Add all machines from inventory to MAAS
33
vars:
44
arch: "amd64" # Change if needed
5-
when: inventory_hostname in groups['maas_region_rack_server'] and maas_installed.failed == false and logged_into_maas.rc == 0
5+
when: inventory_hostname in groups['maas_region_rack_server'] and logged_into_maas.rc == 0
6+
tags: add_machines
67
block:
7-
- name: Get a list of testnodes from the inventory
8-
set_fact:
9-
testnodes_list: "{{ groups['testnodes'] }}"
10-
register: testnodes_listed
8+
- name: Get existing machines in MAAS
9+
command: "maas {{ maas_admin_username }} machines read"
10+
register: existing_machines
1111

12-
- name: Add machines to MAAS
13-
command: "maas {{ maas_admin_username }} machines create deployed=true hostname={{ item }} architecture={{ arch }} mac_addresses={{ hostvars[item]['mac'] }} power_type=manual"
14-
with_items: "{{ testnodes_list }}"
15-
ignore_errors: true
16-
when: hostvars[item]['mac'] is defined and testnodes_listed.changed == true
12+
- name: Extract existing hostnames
13+
set_fact:
14+
existing_hostnames: "{{ existing_machines.stdout | from_json | map(attribute='hostname') | list }}"
15+
16+
- name: Add Machines into MAAS
17+
vars:
18+
hostname: "{{ item.split('.')[0] }}"
19+
mac_address: "{{ hostvars[item]['mac'] }}"
20+
when: hostname not in existing_hostnames and mac_address is defined
21+
loop: "{{ groups['testnodes'] }}"
22+
command: "maas {{ maas_admin_username }} machines create architecture={{ arch }} mac_addresses={{ mac_address }} hostname={{ item }} power_type=manual deployed=true"
23+

0 commit comments

Comments
 (0)