|
1 | 1 | ---
|
2 |
| -- name: Configure MAAS DHCP Service |
3 |
| - when: inventory_hostname in groups['maas_region_rack_server'] and maas_installed.failed == false and logged_into_maas.rc == 0 |
4 |
| - block: |
5 |
| - - name: Get a list of all hosts from the inventory |
6 |
| - set_fact: |
7 |
| - all_list: "{{ groups['all'] }}" |
8 |
| - register: all_nodes_listed |
9 |
| - |
10 |
| - - name: Debugging subnet variable |
11 |
| - debug: |
12 |
| - var: "{{ item }}" |
13 |
| - |
14 |
| - - name: Creating IP Range |
15 |
| - command: "maas admin ipranges create type={{ subnet.ip_range_type }} start_ip={{ subnet.start_ip }} end_ip={{ subnet.end_ip }}" |
16 |
| - ignore_errors: true |
17 |
| - |
18 |
| - - name: Selecting the correct fabric to configure |
19 |
| - command: maas admin subnet read {{ subnet.subnet }}|grep 'fabric-'|cut -d '"' -f 4 |
20 |
| - register: fabric_selected |
21 |
| - |
22 |
| - - name: Getting subnet ID |
23 |
| - command: maas admin subnet read {{ subnet.subnet }}|grep '"id"'|cut -d ':' -f 2|cut -d ',' -f 1|head -1 |
24 |
| - register: subnet_id |
25 |
| - |
26 |
| - - name: Enabling DHCP with HA on the selected subnet |
27 |
| - command: "maas admin vlan update {{ fabric_selected.stdout }} 0 dhcp_on=True primary_rack={{ hostvars[groups['maas_region_rack_server'].0] }} secondary_rack={{ hostvars[groups['maas_rack_server'].0] }}" |
28 |
| - |
29 |
| - - name: Creating temporary snippets directory |
30 |
| - file: |
31 |
| - path: /tmp/snippets |
32 |
| - state: directory |
33 |
| - mode: '0755' |
34 |
| - register: snippets_directory |
35 |
| - |
36 |
| - - name: Copying each subnet classes snippet |
37 |
| - template: |
38 |
| - src: dhcpd.classes.conf.j2 |
39 |
| - dest: "/tmp/snippets/{{ subnet }}_classes_snippet" |
40 |
| - when: subnet.classes is defined and snippets_directory.failed == false |
41 |
| - register: dhcp_classes_config |
42 |
| - |
43 |
| -# - name: Creating DHCP snippets for the classes |
44 |
| -# command: maas admin dhcpsnippets create name=class_{{ item.key }} value="class ""{{ item.key }}"" { |
45 |
| -# "{{ item.value }}"; |
46 |
| -# }" description='DHCP config for class "{{ item.key }}"" subnet="{{ subnet_id.stdout }}"' |
47 |
| -# ignore_errors: true |
48 |
| -# loop: "{{ subnet.classes | dict2items }}" |
49 |
| - |
50 |
| - # - name: Creating DHCP snippets for the pools |
51 |
| - |
52 |
| -# - name: Creating DHCP snippets for all hosts |
53 |
| -# command: "maas admin dhcpsnippets create name="{{ item }}" value="host {{ item }} { |
54 |
| -# hardware ethernet {{ hostvars[item]['mac'] }}; |
55 |
| -# fixed-address {{ hostvars[item]['ip'] }}; |
56 |
| -# }" description="DHCP config for host {{ item }}" subnet="{{ subnet_id.stdout }}"" |
57 |
| -# with_items: "{{ all_list }}" |
58 |
| -# ignore_errors: true |
59 |
| -# when: hostvars[item]['mac'] is defined |
| 2 | +- name: Creating IP Range |
| 3 | + command: "maas admin ipranges create type={{ subnet_data.ip_range_type }} start_ip={{ subnet_data.start_ip }} end_ip={{ subnet_data.end_ip }}" |
| 4 | + ignore_errors: true |
| 5 | + tags: skip |
| 6 | + |
| 7 | +- name: Selecting the correct fabric to configure |
| 8 | + command: bash -c "maas admin subnet read {{ subnet_data.cidr }}|grep 'fabric-'|cut -d '\"' -f 4" |
| 9 | + register: fabric_selected |
| 10 | + |
| 11 | +- name: Getting subnet ID |
| 12 | + command: bash -c "maas admin subnet read {{ subnet_data.cidr }}|grep '\"id\"'|cut -d ':' -f 2|cut -d ',' -f 1|head -1" |
| 13 | + register: subnet_id |
| 14 | + |
| 15 | +- name: Enabling DHCP with HA on the selected subnet |
| 16 | + command: "maas admin vlan update {{ fabric_selected.stdout }} 0 dhcp_on=True primary_rack={{ groups['maas_region_rack_server'][0] }} secondary_rack={{ groups['maas_rack_server'][0] }}" |
| 17 | + |
| 18 | +- name: Creating temporary snippets directory |
| 19 | + file: |
| 20 | + path: /tmp/snippets |
| 21 | + state: directory |
| 22 | + mode: '0755' |
| 23 | + register: snippets_directory |
| 24 | + |
| 25 | +- name: Copying each subnet classes snippet |
| 26 | + template: |
| 27 | + src: dhcpd.classes.conf.j2 |
| 28 | + dest: "/tmp/snippets/{{ subnet_name }}_classes_snippet" |
| 29 | + when: subnet_data.classes is defined and snippets_directory.failed == false |
| 30 | + register: dhcp_classes_config |
| 31 | + |
| 32 | +- name: Copying each subnet pools snippet |
| 33 | + template: |
| 34 | + src: dhcpd.pools.conf.j2 |
| 35 | + dest: "/tmp/snippets/{{ subnet_name }}_pools_snippet" |
| 36 | + when: subnet_data.pools is defined and snippets_directory.failed == false |
| 37 | + register: dhcp_pools_config |
| 38 | + |
| 39 | +- name: Copying each subnet hosts snippet |
| 40 | + template: |
| 41 | + src: dhcpd.hosts.conf.j2 |
| 42 | + dest: "/tmp/snippets/{{ subnet_name }}_hosts_snippet" |
| 43 | + when: snippets_directory.failed == false |
| 44 | + register: dhcp_hosts_config |
| 45 | + |
| 46 | +- name: Slurp classes file content |
| 47 | + slurp: |
| 48 | + src: "/tmp/snippets/{{ subnet_name }}_classes_snippet" |
| 49 | + register: classes_file |
| 50 | + |
| 51 | +- name: Decode and show file contents |
| 52 | + set_fact: |
| 53 | + classes_content: "{{ classes_file.content | b64decode }}" |
| 54 | + |
| 55 | +- name: Debugging classes_content |
| 56 | + debug: |
| 57 | + var: classes_content |
| 58 | + |
| 59 | +- name: Adding classes snippets into MAAS |
| 60 | + command: "maas {{ maas_admin_username }} dhcpsnippets create name='{{ subnet_name }}_classes' value='{{ classes_content }}' description='This snippet configures the classes in {{ subnet_name }} subnet' subnet='{{ subnet_id.stdout }}'" |
| 61 | + when: dhcp_classes_config.failed == false |
| 62 | + ignore_errors: true |
0 commit comments