| 1 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
--- |
| 3 |
#################################################################### |
| 4 |
# WARNING: These are designed specifically for Ansible tests # |
| 5 |
# and should not be used as examples of how to write Ansible roles # |
| 6 |
#################################################################### |
| 7 |
|
| 8 |
# Copyright © Thorsten Glaser <[email protected]> |
| 9 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 10 |
|
| 11 |
- name: Install prerequisites |
| 12 |
ansible.builtin.apt: |
| 13 |
name: |
| 14 |
- iproute2 |
| 15 |
state: present |
| 16 |
install_recommends: false |
| 17 |
update_cache: true |
| 18 |
|
| 19 |
- name: Networking setup, interface |
| 20 |
ansible.builtin.command: |
| 21 |
cmd: "ip link add eth666 type dummy" |
| 22 |
creates: /proc/sys/net/ipv4/conf/eth666/forwarding |
| 23 |
changed_when: true |
| 24 |
|
| 25 |
- name: Networking setup, IPv4 |
| 26 |
ansible.builtin.command: |
| 27 |
cmd: "ip addr change 192.0.2.1/24 dev eth666" |
| 28 |
changed_when: true |
| 29 |
|
| 30 |
- name: Networking setup, link |
| 31 |
ansible.builtin.command: |
| 32 |
cmd: "ip link set up dev eth666" |
| 33 |
changed_when: true |
| 34 |
|
| 35 |
- name: Install KEA servers for DHCP and DHCPv6 |
| 36 |
ansible.builtin.apt: |
| 37 |
name: |
| 38 |
- kea-dhcp4-server |
| 39 |
- kea-dhcp6-server |
| 40 |
state: present |
| 41 |
install_recommends: false |
| 42 |
|
| 43 |
- name: Set up dhcp4 server, network |
| 44 |
ansible.builtin.lineinfile: |
| 45 |
firstmatch: true |
| 46 |
insertafter: '"interfaces-config": [{]' |
| 47 |
line: '"interfaces": [ "eth666" ]' |
| 48 |
path: /etc/kea/kea-dhcp4.conf |
| 49 |
search_string: '"interfaces": [' |
| 50 |
|
| 51 |
- name: Set up dhcp4 server, hooks |
| 52 |
ansible.builtin.lineinfile: |
| 53 |
firstmatch: true |
| 54 |
insertbefore: '"subnet4": ' |
| 55 |
# note: this will fail on architectures other than amd64, but Ubuntu 24.04 does need the full path (Debian trixie is content with just the filename) |
| 56 |
line: '"hooks-libraries": [ { "library": "/usr/lib/x86_64-linux-gnu/kea/hooks/libdhcp_lease_cmds.so" } ],' |
| 57 |
path: /etc/kea/kea-dhcp4.conf |
| 58 |
regexp: '^ *"hooks-libraries":' |
| 59 |
|
| 60 |
- name: Ensure the dhcp4 server is (re)started |
| 61 |
ansible.builtin.service: |
| 62 |
name: kea-dhcp4-server |
| 63 |
state: restarted |
| 64 |
|
| 65 |
- name: Ensure the dhcp6 server is (re)started |
| 66 |
ansible.builtin.service: |
| 67 |
name: kea-dhcp6-server |
| 68 |
state: restarted |
| 69 |
|
| 70 |
# the next tasks are for debugging this integration test if needed |
| 71 |
- name: Show dhcp4 server config |
| 72 |
ansible.builtin.command: |
| 73 |
cmd: "cat /etc/kea/kea-dhcp4.conf" |
| 74 |
changed_when: true |
| 75 |
|
| 76 |
- name: Show dhcp4 server log |
| 77 |
ansible.builtin.command: |
| 78 |
cmd: "journalctl -b -u kea-dhcp4-server" |
| 79 |
changed_when: true |
| 80 |
|
| 81 |
- name: Show dhcp6 server log |
| 82 |
ansible.builtin.command: |
| 83 |
cmd: "journalctl -b -u kea-dhcp6-server" |
| 84 |
changed_when: true |
| 85 |
|
| 86 |
# an example for a request acquiring information |
| 87 |
- name: Get KEA DHCP6 status |
| 88 |
kea_command: |
| 89 |
command: status-get |
| 90 |
rv_unchanged: [0] |
| 91 |
socket: /run/kea/kea6-ctrl-socket |
| 92 |
register: kea6_status |
| 93 |
ignore_errors: true |
| 94 |
|
| 95 |
- name: Display registered status result |
| 96 |
ansible.builtin.debug: |
| 97 |
msg: KEA DHCP6 running on PID {{ kea6_status.response.arguments.pid }} |
| 98 |
|
| 99 |
# ensure socket option works |
| 100 |
- name: Get KEA DHCP4 status |
| 101 |
kea_command: |
| 102 |
command: status-get |
| 103 |
rv_unchanged: [0] |
| 104 |
socket: /run/kea/kea4-ctrl-socket |
| 105 |
register: kea4_status |
| 106 |
ignore_errors: true |
| 107 |
|
| 108 |
# an example for requests modifying state |
| 109 |
- name: Remove existing leases for 192.0.2.66, if any |
| 110 |
kea_command: |
| 111 |
command: lease4-del |
| 112 |
arguments: |
| 113 |
ip-address: "192.0.2.66" |
| 114 |
rv_changed: [0] |
| 115 |
rv_unchanged: [3] |
| 116 |
register: lease_del |
| 117 |
ignore_errors: true |
| 118 |
|
| 119 |
- name: Add DHCP lease for 192.0.2.66 |
| 120 |
kea_command: |
| 121 |
command: lease4-add |
| 122 |
arguments: |
| 123 |
ip-address: "192.0.2.66" |
| 124 |
hw-address: "00:00:5E:00:53:00" |
| 125 |
rv_changed: [0] |
| 126 |
register: lease_add |
| 127 |
ignore_errors: true |
| 128 |
|
| 129 |
# these all ignore_errors so the network teardown runs in all cases |
| 130 |
- name: An unknown command |
| 131 |
kea_command: |
| 132 |
command: get-status |
| 133 |
rv_unchanged: [0] |
| 134 |
register: uc_status |
| 135 |
ignore_errors: true |
| 136 |
|
| 137 |
- name: Networking setup, teardown |
| 138 |
ansible.builtin.command: |
| 139 |
cmd: "ip link del eth666" |
| 140 |
changed_when: true |
| 141 |
|
| 142 |
- name: Ensure dhcp4 and dhcp6 PIDs are different |
| 143 |
ansible.builtin.assert: |
| 144 |
that: |
| 145 |
- kea4_status.response.arguments.pid is integer |
| 146 |
- kea4_status.response.arguments.pid > 0 |
| 147 |
- kea6_status.response.arguments.pid is integer |
| 148 |
- kea6_status.response.arguments.pid > 0 |
| 149 |
- kea4_status.response.arguments.pid != kea6_status.response.arguments.pid |
| 150 |
fail_msg: 'PIDs are invalid or do not differ (4: {{ kea4_status.response.arguments.pid | default("unknown") }}, 6: {{ kea6_status.response.arguments.pid | default("unknown") }})' |
| 151 |
success_msg: 'PIDs differ (4: {{ kea4_status.response.arguments.pid | default("unknown") }}, 6: {{ kea6_status.response.arguments.pid | default("unknown") }})' |
| 152 |
|
| 153 |
- name: Check results |
| 154 |
ansible.builtin.assert: |
| 155 |
that: |
| 156 |
- kea6_status is not changed |
| 157 |
- kea6_status is not failed |
| 158 |
- kea4_status is not changed |
| 159 |
- kea4_status is not failed |
| 160 |
- lease_del is not failed |
| 161 |
- lease_add is changed |
| 162 |
- lease_add is not failed |
| 163 |
- uc_status is failed |