From: Fernando Date: Wed, 14 May 2025 16:00:50 +0000 (-0600) Subject: Resolving some comments on the code X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=afa9f0f3e6edb980eacaf971c4a44a26331f7fb2;p=ceph-cm-ansible.git Resolving some comments on the code Signed-off-by: Fernando --- diff --git a/roles/maas/README.md b/roles/maas/README.md index 1e37808..5ba0af9 100644 --- a/roles/maas/README.md +++ b/roles/maas/README.md @@ -7,7 +7,7 @@ This Ansible playbook automates the installation and initial configuration of [M - 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 @@ -62,6 +62,7 @@ dhcp_maas_global: - 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: @@ -99,7 +100,7 @@ Here's a line from our Ansible inventory host file 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. @@ -146,4 +147,4 @@ maas - 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. diff --git a/roles/maas/tasks/config_dhcpd_subnet.yml b/roles/maas/tasks/config_dhcpd_subnet.yml index 6821ccb..4ac3b11 100644 --- a/roles/maas/tasks/config_dhcpd_subnet.yml +++ b/roles/maas/tasks/config_dhcpd_subnet.yml @@ -1,10 +1,10 @@ --- -- 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 @@ -13,26 +13,26 @@ 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 @@ -41,7 +41,7 @@ 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 @@ -49,7 +49,7 @@ 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" @@ -58,29 +58,29 @@ # 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 @@ -148,18 +148,18 @@ # 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 diff --git a/roles/maas/tasks/initialize_region_rack.yml b/roles/maas/tasks/initialize_region_rack.yml index 70b8035..c41e6b7 100644 --- a/roles/maas/tasks/initialize_region_rack.yml +++ b/roles/maas/tasks/initialize_region_rack.yml @@ -3,10 +3,11 @@ 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: diff --git a/roles/maas/tasks/initialize_secondary_rack.yml b/roles/maas/tasks/initialize_secondary_rack.yml index 1c50a2d..6f8a612 100644 --- a/roles/maas/tasks/initialize_secondary_rack.yml +++ b/roles/maas/tasks/initialize_secondary_rack.yml @@ -1,5 +1,5 @@ --- -- 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 @@ -9,10 +9,11 @@ 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'] }}" diff --git a/roles/maas/tasks/main.yml b/roles/maas/tasks/main.yml index 5f20842..8eaf18c 100644 --- a/roles/maas/tasks/main.yml +++ b/roles/maas/tasks/main.yml @@ -43,15 +43,13 @@ - 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 @@ -77,5 +75,4 @@ - 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'] diff --git a/roles/maas/templates/dhcpd.classes.conf.j2 b/roles/maas/templates/dhcpd.classes.conf.j2 deleted file mode 100644 index b9cbad6..0000000 --- a/roles/maas/templates/dhcpd.classes.conf.j2 +++ /dev/null @@ -1,8 +0,0 @@ - {% if subnet_data.classes is defined -%} - {% for class_name, class_string in subnet_data.classes.items() -%} - class "{{ class_name }}" { - {{ class_string }}; - } - - {% endfor -%} - {%- endif -%} diff --git a/roles/maas/templates/dhcpd.classes.snippet.j2 b/roles/maas/templates/dhcpd.classes.snippet.j2 new file mode 100644 index 0000000..b9cbad6 --- /dev/null +++ b/roles/maas/templates/dhcpd.classes.snippet.j2 @@ -0,0 +1,8 @@ + {% if subnet_data.classes is defined -%} + {% for class_name, class_string in subnet_data.classes.items() -%} + class "{{ class_name }}" { + {{ class_string }}; + } + + {% endfor -%} + {%- endif -%} diff --git a/roles/maas/templates/dhcpd.global.conf.j2 b/roles/maas/templates/dhcpd.global.conf.j2 deleted file mode 100644 index 027b09b..0000000 --- a/roles/maas/templates/dhcpd.global.conf.j2 +++ /dev/null @@ -1,5 +0,0 @@ -{% for item in dhcp_maas_global %} -{% for key, value in item.items() %} -{{ key }} {{ value }}; -{% endfor %} -{% endfor %} diff --git a/roles/maas/templates/dhcpd.global.snippet.j2 b/roles/maas/templates/dhcpd.global.snippet.j2 new file mode 100644 index 0000000..027b09b --- /dev/null +++ b/roles/maas/templates/dhcpd.global.snippet.j2 @@ -0,0 +1,5 @@ +{% for item in dhcp_maas_global %} +{% for key, value in item.items() %} +{{ key }} {{ value }}; +{% endfor %} +{% endfor %} diff --git a/roles/maas/templates/dhcpd.hosts.conf.j2 b/roles/maas/templates/dhcpd.hosts.conf.j2 deleted file mode 100644 index d1d8013..0000000 --- a/roles/maas/templates/dhcpd.hosts.conf.j2 +++ /dev/null @@ -1,16 +0,0 @@ - {% 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 -%} diff --git a/roles/maas/templates/dhcpd.hosts.snippet.j2 b/roles/maas/templates/dhcpd.hosts.snippet.j2 new file mode 100644 index 0000000..d1d8013 --- /dev/null +++ b/roles/maas/templates/dhcpd.hosts.snippet.j2 @@ -0,0 +1,16 @@ + {% 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 -%} diff --git a/roles/maas/templates/dhcpd.pools.conf.j2 b/roles/maas/templates/dhcpd.pools.conf.j2 deleted file mode 100644 index 2d7af05..0000000 --- a/roles/maas/templates/dhcpd.pools.conf.j2 +++ /dev/null @@ -1,23 +0,0 @@ - {% 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 -%} diff --git a/roles/maas/templates/dhcpd.pools.snippet.j2 b/roles/maas/templates/dhcpd.pools.snippet.j2 new file mode 100644 index 0000000..2d7af05 --- /dev/null +++ b/roles/maas/templates/dhcpd.pools.snippet.j2 @@ -0,0 +1,23 @@ + {% 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 -%}