Commit a63528ff authored by julian.gethmann's avatar julian.gethmann Committed by julian.gethmann

Generalise DHCPd role for TGU and LASMagLab

(untested)
* generalise the role
* Use DHCPd role for lab

* Add TGU role stub! WIP
parent ffcbb766
- hosts: dhcpd
vars:
- dhcpd:
domain: las.kit.edu
subnet: 129.13.108.0
netmask: 255.255.255.0
range_start: 129.13.108.74
range_end: 129.13.108.89
routers: 129.13.108.254
broadcast: 129.13.255.255
host_list: host-list-las
roles:
- dhcpd
- hosts: lab
vars:
- dhcpd:
domain: maglab
subnet: 192.168.0.0
netmask: 255.255.255.0
range_start: 192.168.0.1
range_end: 192.168.0.100
routers: 192.168.0.10
broadcast: 192.168.0.255
host_list: host-list-maglab
roles:
- lab
- dhcpd
- lab
---
- name: dhcpd installed
- name: Load OS dependent variables
include_vars: '{{ item }}'
with_first_found:
- files:
- 'vars/{{ ansible_os_family }}.yml'
errors: ignore
tags: dhcpd
- name: dhcpd installed (Debian)
become: true
dnf:
name: dhcp
state: installed
package:
name: "{{ pkg_name }}"
state: present
notify:
- start dhcpd
- enable dhcpd
......@@ -11,17 +19,15 @@
- name: copy mac addresses and config
become: true
copy:
src: "{{ item }}"
dest: "/etc/dhcp/{{ item }}"
src: "{{ dhcpd.host_list }}"
dest: "/etc/dhcp/{{ dhcpd.host_list }}"
backup: yes
owner: root
group: root
validate: /sbin/dhcpd -t -cf %s
owner: dhcpd
group: dhcpd
mode: 0644
validate: "{{ bin_path }} -t -cf %s"
decrypt: yes
notify: restart dhcpd
with_items:
- "host-list-las"
- dhcpd.conf
- name: install dhcpd config
become: true
......@@ -29,5 +35,8 @@
src: dhcpd.j2
dest: /etc/dhcp/dhcpd.conf
backup: yes
validate: /sbin/dhcpd -t -cf %s
owner: dhcpd
group: dhcpd
mode: 0644
validate: "{{ bin_path }} -t -cf %s"
notify: restart dhcpd
......@@ -8,7 +8,7 @@
#
# option definitions common to all supported networks...
option domain-name "las.kit.edu";
option domain-name "{{ dhcpd.domain }}";
option domain-name-servers 129.13.64.5, 129.13.96.2;
default-lease-time 60;
......@@ -25,6 +25,7 @@ authoritative;
# have to hack syslog.conf to complete the redirection).
log-facility local7;
{% if failover %}
# failover https://www.madboa.com/geek/dhcp-failover/
# https://kb.isc.org/article/AA-00502/0/A-Basic-Guide-to-Configuring-DHCP-Failover.html
failover peer "dhcp-failover" {
......@@ -51,20 +52,24 @@ failover peer "dhcp-failover" {
split 128;
{% endif %}
}
{% endif %}
# A slightly different configuration for an internal subnet.
subnet 129.13.108.0 netmask 255.255.255.0 {
option routers 129.13.108.254;
option broadcast-address 129.13.255.255;
option domain-name "las.kit.edu";
subnet {{ dhcpd.subnet }} netmask {{ dhcpd.netmask }} {
option routers {{ dhcpd.routers }};
option broadcast-address {{ dhcpd.broadcast }};
option domain-name "{{ dhcpd.domain }}";
option domain-name-servers 129.13.64.5, 129.13.96.2;
#
default-lease-time 1800;
max-lease-time 7200;
deny unknown-clients;
range {{ dhcpd.range_start }} {{ dhcpd.range_end }};
{% if failover %}
pool {
failover peer "dhcp-failover";
default-lease-time 1800;
max-lease-time 7200;
range 129.13.108.70 129.13.108.89;
deny unknown-clients;
}
{% endif %}
}
include "/etc/dhcp/host-list-las";
include "/etc/dhcp/{{ dhcpd.host_list }}";
---
service_name: isc-dhcp-server
pkg_name: isc-dhcp-server
bin_path: /usr/sbin/dhcpd
---
service_name: dhcpd
pkg_name: dhcp
bin_path: /sbin/dhcpd
This diff is collapsed.
---
- name: Load OS dependent variables
include_vars: '{{ item }}'
with_first_found:
- files:
- 'vars/{{ ansible_os_family }}.yml'
errors: ignore
tags: dhcpd
- name: dhcpd installed (Debian)
become: true
apt:
name: "{{ pkg_name }}"
state: present
notify:
- start dhcpd
- enable dhcpd
when: ansible_os_family == "Debian"
- name: dhcpd installed (RedHat)
become: true
dnf:
name: "{{ pkg_name }}"
state: present
notify:
- start dhcpd
- enable dhcpd
when: ansible_distribution == "Fedora"
- name: copy mac addresses and config
become: true
copy:
src: "{{ item }}"
dest: "/etc/dhcp/{{ item }}"
backup: yes
owner: dhcpd
group: dhcpd
mode: 0644
decrypt: yes
# https://superuser.com/questions/1286948/ansible-template-validation-fails-on-isc-dhcp-server
# validate: "{{ bin_path }} -t -cf %s"
notify: restart dhcpd
with_items:
- "host-list-maglab"
- dhcpd.conf
- name: set host in hosts file
lineinfile:
path: /etc/hosts
......
# $Ansible managed: /etc/ssh/ssh_config.d/06-rpi.conf
Host pi
User pi
HostName 192.168.127.5
ForwardX11 yes
$ANSIBLE_VAULT;1.1;AES256
62333066643230656432666638356532316637393032373566373865636531373965646164373363
3533643033376535323839646665323536303833626634640a303330306366373335393037303833
65653263346538613831353866643664633936626536623739303262346433336135623431373532
3662616561346638380a333230386562333833653935623366306261393232366531316262623865
61376138376361346365653730646533656136393138333231343033333464346232373834303735
32313661613937306438646262353233323463613964653664636435323438666236333232623962
32356337303231303732383034626166353837623965323931643432633962363130636239343965
62613563666639623566363663623962333862333161646561383062376530313233623834323533
63383430633637383639336636613436363931303561303338373961306263643466653937626236
61336432306235663835666237323362333834306437396165373061346137343363346533653666
31633430626461623438333631663031343832666133366231633632343963333430376566653037
39393932626463663735333161353430383765363030663436633331373530636565663966666333
36376564376163653236643834313663366136343065616536636566393836646230363134393366
32383061346662393361646136383931653566663036366666323434613532616362316235656339
31353162313433656463383336613765313166663562646162336130393434663337653231636534
36613437363734613933336437303539376330363466616331303764613561316233383536636431
64643531313738306132623363333063623836623135376131396337346661613763386137356331
35643932643434643334363933623161666262653066376433663961653132356464373036643434
39626535383066626634363935303533616166363761376635396237356335636536393461646561
38346532383833326466626266313331386631656463616162653532623539303466646333393063
34376530363139373663323938393665633562653634613235393937326339313666393335343262
33373365366637616434313066333236396435646339646132393531393264343866383964396434
65306238373264323364366134373364343838666165633637643765326631386561356533336363
31333130653038316532643066383963343836383030336161306537646539393566343466613463
34346463646164323838323138663063653366386530613763363834303138646539313538323439
63613065323935363363386235353564623037316563303065366532316562373762356634383065
66663662346530643037333866393237663838336538323963633336653030343661393435656564
39393666663732366330386132633962333137363938646438386338666334633130366331643664
66306638333832306562343532313637666262333532303830353266326336643262346234376661
62306236363262373965613239323361656563363333626234313239316161656235353932373065
37636531623065373164613235333232303565303964663562633030643165353330376136343136
33303239363434346439386233613035626332343162393162373136646533643636336237303465
64353234323930653162333365393763623165636334343661356136376334383532393133393334
32383837376639393062613165616566306132333361616665333534386261653965353361323066
38383162313963343261333664396166306264313734333661633230383761393066343166666334
63353562306230633230316432626530666365316538383461663138653161346139626264306437
38343633393363333936373331346462663261636663343936653336613136336638333738613137
38646431306263313936623035616533366532376536646532626563303066616664626633636365
38623639333635663761376461613261393433323430653638626134363232343737376666383133
34313664633636626161626235323133376237353764383537353764656636633264646461376266
65356335376131663966623266353962373434633164386632663363333934383533613931316234
37663666326337626664356338366632646461316235366661346263386338373733613837363435
38383033306139353463333961363964393463343730303330306261636565643066383432653865
35346534326666386639633863393530333239363130343466376566313831356637383864343632
32343837386463636231656163356339346537623661623664626235313062356535646236353637
64636536323465383364313464343764393939323662383236613365653863353333623533623134
31396363646461626134356633643238323835336237313764313935633037366666333733353537
37323863396263303338323535313061663335646438643661323764653964383164303433626362
64336537363861323937366665363231306332616536623163376266306165633531376236626631
30303834666163666230636332353163383866313637356131373165306439363232616634366439
36663837333631626439393236393539616466643234376364636163643236323239623436313338
62366463363138623931343731656538613430313938623361653664616332363236386564356638
34316465313232373965663531363836626331346332376435346665346537326633353164663964
31343937303262356639666563316331636662333535356436353834383464343630656133306132
61363738386336356432323365363666333165396262616462613334623332666235643334333339
33366139653034663831656435613137626463653531343063656631316464313766616532656566
33653731376366626634303432633432363132626663666631356331336637313438363162396463
62666630663033363838373430336635356238313330663365333130643032353765613334323765
62626162663465313132623731323935306239363236653336623731313836356363393539373932
39396332393036623239316633386238646233633332383162633534346137303662363030303131
66336533326532383638326437313665356231346230303865366666623437356465653266353234
63626233373438653463306437636165636639323562363433643635633666383764303535653866
37383539363435373433383136633262396633613033303335386465326330306334653830663631
38633635343630326362336661303136663537616563616632396231326237373562346365393437
37313261363634653761646530396537356138376161353231303438633132623739353538343533
35373162326235306663303264663362643438366330616331316466363661646663366566316366
38373664306563616235303861343637663736316232396465396335343063643531666330636461
38323238356131343539353864373963626532356661636237353934613930363531643231653738
35383666666230356566666134323662303464313962613339666566646165663038653765346666
66306431366436666535333739396366643635336334643866356532353431623138623661303766
32626263633266336438373963306362653362616534353561363234643536326138363164633336
62333765623134363561326537353738653331643265323139373835326364613935373838363930
65303436353636623434393738643730393264386162346237663861333039373637393666666164
31373639326430316537303133346338623736656134326265633836663365613438613730363636
31363332313036343462366462363636323162303539353137643439643737626339336434633833
37363039353335386333653336343436336532323564373264383437343662366435643261376535
34323963333438383936326239646430353661326661333964623232363031303066343530346634
31323763356234616339316264376336626464616335616335313939396266626231366238666466
643935383963333031313166373762303137
---
- name: copy short cuts for ssh
copy:
name: 06-rpi.conf
dest: /etc/ssh/ssh_config.d/06-rpi.conf
- hosts: tgulab
vars:
- dhcpd:
domain: cn-tgu
subnet: 192.168.127.0
netmask: 255.255.255.0
range_start: 192.168.127.1
range_end: 192.168.127.100
routers: 192.168.127.10
broadcast: 192.168.127.255
host_list: host-list-cn-tgu
roles:
- dhcpd
- tgulab
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment