|
| 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. |
0 commit comments