- Installs MAAS packages
- Initializes MAAS with a default user with High Availability
- Configures networking (DHCP, DNS, etc.)
-- Adds Machines from invetory into MAAS
+- Adds Machines from inventory into MAAS
## Requirements
- one-lease-per-client: "true"
This list will be used to populate the global DHCP snippet. You can add additional keys and values. Just make sure they follow the syntax required for dhcpd.conf.
+The global configuration is optional, so you can just remove the elements of the list if you do not need them.
dhcp_maas_subnets: #This is a list of dictionaries, you can list here all the subnets you want to configure and use any name you want in this case we use front and back but you can include here any other or change the names.
front:
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
-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.
+This will result in a static lease 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.
start_ip, end_ip and ip_range_type are required too in order to create an IP range. MAAS needs a range in order to enable DHCP on the subnet. In this case the ip_range_type is configured as dynamic, it could be dynamic or static.
- install_maas #Install MAAS and postgreSQL only and initializes the region+rack server and the secondary rack.
- add-machines #Add Machines to MAAS only if they are not already present.
- config_dhcp #Configures DHCP options only if there are any change in the DHCP variables.
-- config_dns #Configure DNS domains and add the DNS Records that are not currenlty into a domain.
+- config_dns #Configure DNS domains and add the DNS Records that are not currently into a domain.
---
-- name: Configures MAAS DHCP
+- name: Configure MAAS DHCP
when: inventory_hostname in groups['maas_region_rack_server']
tags: config_dhcp
block:
# This section enables DHCP on the subnets included into the secrets repo group_vars and creates an IP range for them
- - name: Verifying available ipranges
+ - name: Read maas ipranges
command: "maas {{ maas_admin_username }} ipranges read"
register: ip_ranges_raw
existing_start_ips: "{{ ip_ranges_raw.stdout | from_json | map(attribute='start_ip') | list }}"
existing_end_ips: "{{ ip_ranges_raw.stdout | from_json | map(attribute='end_ip') | list }}"
- - name: Creating IP Range for {{ subnet_name }} subnet
+ - name: Create IP Range for {{ subnet_name }} subnet
command: "maas {{ maas_admin_username }} ipranges create type={{ subnet_data.ip_range_type }} start_ip={{ subnet_data.start_ip }} end_ip={{ subnet_data.end_ip }}"
when: subnet_data.start_ip not in existing_start_ips and subnet_data.end_ip not in existing_end_ips
- - name: Getting subnet information
+ - name: Read maas subnet information
command: "maas {{ maas_admin_username }} subnet read {{ subnet_data.cidr }}"
register: subnet_info
- - name: Defining subnet variables
+ - name: Define subnet variables
set_fact:
- fabric_name: "{{ subnet_info.stdout | from_json | json_query('vlan.fabric') }}"
- vlan_vid: "{{ subnet_info.stdout | from_json | json_query('vlan.vid') }}"
- vlan_id: "{{ subnet_info.stdout | from_json | json_query('vlan.id') }}"
+ fabric_name: "{{ (subnet_info.stdout | from_json).vlan.fabric }}"
+ vlan_vid: "{{ (subnet_info.stdout | from_json).vlan.vid }}"
+ vlan_id: "{{ (subnet_info.stdout | from_json).vlan.id }}"
- - name: Enabling DHCP on {{ subnet_name }} subnet
+ - name: Enable DHCP on {{ subnet_name }} subnet
command: "maas {{ maas_admin_username }} vlan update {{ fabric_name }} {{ vlan_vid }} dhcp_on=True primary_rack={{ groups['maas_region_rack_server'][0] }} secondary_rack={{ groups['maas_rack_server'][0] }}"
# This task creates the directory where the snippets are going to be copied
- - name: Creating snippets directory
+ - name: Create snippets directory
file:
path: /var/snap/maas/common/maas/dhcp/snippets
state: directory
failed_when: snippets_directory.failed == true
# This section verifies if the snippets already exist and creates the name variables
- - name: Getting current snippet names
+ - name: Get current snippet names
command: bash -c "maas {{ maas_admin_username }} dhcpsnippets read"
register: current_snippets
set_fact:
existing_snippets: "{{ current_snippets.stdout | from_json | map(attribute='name') | list }}"
- - name: Defining snippet name variables
+ - name: Define snippet name variables
set_fact:
global_snippet: "global_dhcp"
classes_snippet: "{{ subnet_name }}_classes"
# This section copies the snippets
- - name: Copying global DHCP snippet
+ - name: Copy global DHCP snippet
template:
- src: dhcpd.global.conf.j2
+ src: dhcpd.global.snippet.j2
dest: "/var/snap/maas/common/maas/dhcp/snippets/global_dhcp_snippet"
register: dhcp_global_config
- - name: Copying {{ subnet_name }} subnet classes snippet
+ - name: Copy {{ subnet_name }} subnet classes snippet
template:
- src: dhcpd.classes.conf.j2
+ src: dhcpd.classes.snippet.j2
dest: "/var/snap/maas/common/maas/dhcp/snippets/{{ subnet_name }}_classes_snippet"
when: subnet_data.classes is defined
register: dhcp_classes_config
- - name: Copying {{ subnet_name }} subnet pools snippet
+ - name: Copy {{ subnet_name }} subnet pools snippet
template:
- src: dhcpd.pools.conf.j2
+ src: dhcpd.pools.snippet.j2
dest: "/var/snap/maas/common/maas/dhcp/snippets/{{ subnet_name }}_pools_snippet"
when: subnet_data.pools is defined
register: dhcp_pools_config
- - name: Copying {{ subnet_name }} subnet hosts snippet
+ - name: Copy {{ subnet_name }} subnet hosts snippet
template:
- src: dhcpd.hosts.conf.j2
+ src: dhcpd.hosts.snippet.j2
dest: "/var/snap/maas/common/maas/dhcp/snippets/{{ subnet_name }}_hosts_snippet"
register: dhcp_hosts_config
# This section adds snippets into MAAS
- - name: Adding global DHCP snippets into MAAS
+ - name: Add global DHCP snippets into MAAS
command: "maas {{ maas_admin_username }} dhcpsnippets create name='{{ global_snippet }}' value='{{ global_content }}' description='This snippet configures the global DHCP options' global_snippet=true"
when: dhcp_global_config.failed == false and dhcp_global_config.changed == true
- - name: Adding {{ subnet_name }} classes snippets into MAAS
+ - name: Add {{ subnet_name }} classes snippets into MAAS
command: "maas {{ maas_admin_username }} dhcpsnippets create name='{{ classes_snippet }}' value='{{ classes_content }}' description='This snippet configures the classes in {{ subnet_name }} subnet' subnet='{{ vlan_id }}'"
when: dhcp_classes_config.failed == false and dhcp_classes_config.changed == true
- - name: Adding {{ subnet_name }} pools snippets into MAAS
+ - name: Add {{ subnet_name }} pools snippets into MAAS
command: "maas {{ maas_admin_username }} dhcpsnippets create name='{{ pools_snippet }}' value='{{ pools_content }}' description='This snippet configures the pools in {{ subnet_name }} subnet' subnet='{{ vlan_id }}'"
when: dhcp_pools_config.failed == false and dhcp_pools_config.changed == true
- - name: Adding {{ subnet_name }} hosts snippets into MAAS
+ - name: Add {{ subnet_name }} hosts snippets into MAAS
command: "maas {{ maas_admin_username }} dhcpsnippets create name='{{ hosts_snippet }}' value='{{ hosts_content }}' description='This snippet configures the hosts in {{ subnet_name }} subnet' subnet='{{ vlan_id }}'"
when: dhcp_hosts_config.failed == false and dhcp_hosts_config.changed == true
when: inventory_hostname in groups['maas_region_rack_server'] and maas_install.failed == false and maas_install.changed == true
tags: install_maas
block:
- - name: Removing conflicting NTP
- apt:
- name: ntp
- state: absent
+ - name: Disable timesyncd service
+ systemd_service:
+ name: systemd-timesyncd
+ state: stopped
+ enabled: false
- name: Initialize MAAS Region Controller
expect:
---
-- name: Generate secret variable
+- name: Get secret for init-rack
command: "cat /var/snap/maas/common/maas/secret"
when: inventory_hostname in groups['maas_region_rack_server'] and maas_install.failed == false and maas_install.changed == true
tags: install_maas
when: inventory_hostname in groups['maas_rack_server'] and maas_install.failed == false and secret_var is defined and maas_install.changed == true
tags: install_maas
block:
- - name: Removing conflicting NTP
- apt:
- name: ntp
- state: absent
+ - name: Disable timesyncd service
+ systemd_service:
+ name: systemd-timesyncd
+ state: stopped
+ enabled: false
- name: Register Rack Controller with Region Controller
command: "maas init rack --maas-url http://{{ hostvars['test1']['ip'] }}:5240/MAAS/ --secret {{ hostvars['test1']['secret_var']['stdout'] }}"
- config_dns
register: maas_api_key
-- name: Logging into MAAS API
+- name: Log into MAAS API
command: "maas login {{ maas_admin_username }} http://{{ hostvars[groups['maas_region_rack_server'].0]['ip'] }}:5240/MAAS/api/2.0/ {{ maas_api_key.stdout }}"
when: inventory_hostname in groups['maas_region_rack_server']
tags:
- config_dhcp
- add_machines
- config_dns
- register: logged_into_maas
- failed_when: logged_into_maas.rc != 0
# Configure DNS Service
- import_tasks: config_dns.yml
- config_dhcp
- add_machines
- config_dns
- when: inventory_hostname in groups['maas_region_rack_server'] and logged_into_maas.rc == 0
-
+ when: inventory_hostname in groups['maas_region_rack_server']
+++ /dev/null
- {% if subnet_data.classes is defined -%}
- {% for class_name, class_string in subnet_data.classes.items() -%}
- class "{{ class_name }}" {
- {{ class_string }};
- }
-
- {% endfor -%}
- {%- endif -%}
--- /dev/null
+ {% if subnet_data.classes is defined -%}
+ {% for class_name, class_string in subnet_data.classes.items() -%}
+ class "{{ class_name }}" {
+ {{ class_string }};
+ }
+
+ {% endfor -%}
+ {%- endif -%}
+++ /dev/null
-{% for item in dhcp_maas_global %}
-{% for key, value in item.items() %}
-{{ key }} {{ value }};
-{% endfor %}
-{% endfor %}
--- /dev/null
+{% for item in dhcp_maas_global %}
+{% for key, value in item.items() %}
+{{ key }} {{ value }};
+{% endfor %}
+{% endfor %}
+++ /dev/null
- {% for host in groups['all'] | sort | unique -%}
- {% if hostvars[host][subnet_data.macvar] is defined -%}
- {% if hostvars[host][subnet_data.ipvar] | ansible.utils.ipaddr(subnet_data.cidr) -%}
- host {{ host.split('.')[0] }}-{{ subnet_name }} {
- {% if hostvars[host]['domain_name_servers'] is defined -%}
- option domain-name-servers {{ hostvars[host]['domain_name_servers']|join(', ') }};
- {% endif -%}
- hardware ethernet {{ hostvars[host][subnet_data.macvar] }};
- fixed-address {{ hostvars[host][subnet_data.ipvar] }};
- {% if hostvars[host]['dhcp_option_hostname'] is defined and hostvars[host]['dhcp_option_hostname'] == true %}
- option host-name "{{ host.split('.')[0] }}";
- {% endif -%}
- }
- {% endif -%}
- {% endif -%}
- {% endfor -%}
--- /dev/null
+ {% for host in groups['all'] | sort | unique -%}
+ {% if hostvars[host][subnet_data.macvar] is defined -%}
+ {% if hostvars[host][subnet_data.ipvar] | ansible.utils.ipaddr(subnet_data.cidr) -%}
+ host {{ host.split('.')[0] }}-{{ subnet_name }} {
+ {% if hostvars[host]['domain_name_servers'] is defined -%}
+ option domain-name-servers {{ hostvars[host]['domain_name_servers']|join(', ') }};
+ {% endif -%}
+ hardware ethernet {{ hostvars[host][subnet_data.macvar] }};
+ fixed-address {{ hostvars[host][subnet_data.ipvar] }};
+ {% if hostvars[host]['dhcp_option_hostname'] is defined and hostvars[host]['dhcp_option_hostname'] == true %}
+ option host-name "{{ host.split('.')[0] }}";
+ {% endif -%}
+ }
+ {% endif -%}
+ {% endif -%}
+ {% endfor -%}
+++ /dev/null
- {% if subnet_data.pools is defined -%}
- {% for pool, pool_value in subnet_data.pools.items() -%}
- pool {
- {% if pool == "unknown_clients" -%}
- allow unknown-clients;
- {% else -%}
- allow members of "{{ pool }}";
- {% endif -%}
- {% if pool_value.range is string -%}
- range {{ pool_value.range }};
- {% else -%}
- range {{ pool_value.range|join(';\n range ') }};
- {% endif -%}
- {% if pool_value.next_server is defined -%}
- next-server {{ pool_value.next_server }};
- {% endif -%}
- {% if pool_value.filename is defined -%}
- filename "{{ pool_value.filename }}";
- {% endif -%}
- }
-
- {% endfor -%}
- {%- endif -%}
--- /dev/null
+ {% if subnet_data.pools is defined -%}
+ {% for pool, pool_value in subnet_data.pools.items() -%}
+ pool {
+ {% if pool == "unknown_clients" -%}
+ allow unknown-clients;
+ {% else -%}
+ allow members of "{{ pool }}";
+ {% endif -%}
+ {% if pool_value.range is string -%}
+ range {{ pool_value.range }};
+ {% else -%}
+ range {{ pool_value.range|join(';\n range ') }};
+ {% endif -%}
+ {% if pool_value.next_server is defined -%}
+ next-server {{ pool_value.next_server }};
+ {% endif -%}
+ {% if pool_value.filename is defined -%}
+ filename "{{ pool_value.filename }}";
+ {% endif -%}
+ }
+
+ {% endfor -%}
+ {%- endif -%}