From 750dc27d460b3266f040a83f62856762d45b2965 Mon Sep 17 00:00:00 2001 From: pgrondek Date: Sun, 29 Nov 2020 01:12:15 +0100 Subject: [PATCH] Network --- localhost.yml | 2 +- roles/dns/tasks/dns-file.yml | 8 -- roles/dns/templates/etc/bind/db.lan.j2 | 17 ---- roles/network/tasks/dhcp-file.yml | 12 +++ roles/network/tasks/dns-file.yml | 14 +++ roles/{dns => network}/tasks/main.yml | 1 + roles/network/templates/etc/bind/db.lan.j2 | 17 ++++ .../network/templates/etc/dhcpd/dhcpd.conf.j2 | 20 ++++ roles/{dns => network}/vars/main.yml | 98 ++++++++++++------- 9 files changed, 127 insertions(+), 62 deletions(-) delete mode 100644 roles/dns/tasks/dns-file.yml delete mode 100644 roles/dns/templates/etc/bind/db.lan.j2 create mode 100644 roles/network/tasks/dhcp-file.yml create mode 100644 roles/network/tasks/dns-file.yml rename roles/{dns => network}/tasks/main.yml (53%) create mode 100644 roles/network/templates/etc/bind/db.lan.j2 create mode 100644 roles/network/templates/etc/dhcpd/dhcpd.conf.j2 rename roles/{dns => network}/vars/main.yml (62%) diff --git a/localhost.yml b/localhost.yml index 012d3c8..8370992 100644 --- a/localhost.yml +++ b/localhost.yml @@ -1,4 +1,4 @@ --- - hosts: localhost roles: - - dns + - network diff --git a/roles/dns/tasks/dns-file.yml b/roles/dns/tasks/dns-file.yml deleted file mode 100644 index e42fad5..0000000 --- a/roles/dns/tasks/dns-file.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Create db.lan -# become: yes - template: - src: etc/bind/db.lan.j2 - dest: /tmp/etc/bind/db.lan - vars: - diff --git a/roles/dns/templates/etc/bind/db.lan.j2 b/roles/dns/templates/etc/bind/db.lan.j2 deleted file mode 100644 index 7f6f3aa..0000000 --- a/roles/dns/templates/etc/bind/db.lan.j2 +++ /dev/null @@ -1,17 +0,0 @@ -$TTL 86400 -$ORIGIN lan. -@ IN SOA lan. dns.lan. ( - 2020072901; - 604800; - 86400; - 2419200; - 86400; -) - -@ IN NS dns.lan. - -DNS IN A {{ network }}.100 - -{% for host in hosts %} -{{ host.name }} IN A {{ network }}.{{ host.ip }} -{% endfor %} \ No newline at end of file diff --git a/roles/network/tasks/dhcp-file.yml b/roles/network/tasks/dhcp-file.yml new file mode 100644 index 0000000..e5599f7 --- /dev/null +++ b/roles/network/tasks/dhcp-file.yml @@ -0,0 +1,12 @@ +--- +- name: create build directory + file: + path: build/dhcp + state: directory + +- name: Create dhcpd.conf + template: + src: etc/dhcpd/dhcpd.conf.j2 + dest: build/dhcp/dhcpd.conf + vars: + network: "{{ lan }}" \ No newline at end of file diff --git a/roles/network/tasks/dns-file.yml b/roles/network/tasks/dns-file.yml new file mode 100644 index 0000000..10069dc --- /dev/null +++ b/roles/network/tasks/dns-file.yml @@ -0,0 +1,14 @@ +--- +- name: create build directory + file: + path: build/dns + state: directory + +- name: Create db.lan +# become: yes + template: + src: etc/bind/db.lan.j2 + dest: build/dns/db.lan + vars: + network: "{{ lan }}" + serial: "{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}02" diff --git a/roles/dns/tasks/main.yml b/roles/network/tasks/main.yml similarity index 53% rename from roles/dns/tasks/main.yml rename to roles/network/tasks/main.yml index 05502e9..cb154d5 100644 --- a/roles/dns/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -1,3 +1,4 @@ --- - import_tasks: dns-file.yml +- import_tasks: dhcp-file.yml diff --git a/roles/network/templates/etc/bind/db.lan.j2 b/roles/network/templates/etc/bind/db.lan.j2 new file mode 100644 index 0000000..46ecb2c --- /dev/null +++ b/roles/network/templates/etc/bind/db.lan.j2 @@ -0,0 +1,17 @@ +$TTL 86400 +$ORIGIN {{ network.network_name }}. +@ IN SOA {{ network.network_name }}. dns.{{ network.network_name }}. ( + {{ serial }}; + 604800; + 86400; + 2419200; + 86400; +) + +@ IN NS dns.lan. + +DNS IN A {{ network.network_prefix }}.100 + +{% for host in network.hosts %} +{{ host.name }} IN A {{ network.network_prefix }}.{{ host.ip }} +{% endfor %} \ No newline at end of file diff --git a/roles/network/templates/etc/dhcpd/dhcpd.conf.j2 b/roles/network/templates/etc/dhcpd/dhcpd.conf.j2 new file mode 100644 index 0000000..71f2e60 --- /dev/null +++ b/roles/network/templates/etc/dhcpd/dhcpd.conf.j2 @@ -0,0 +1,20 @@ +ddns-update-style none; +authorative; + +subnet {{ network.address }} netmask {{ network.mask }} { + option domain-name-servers {{ network.dns }}; + option domain-name "{{ network.network_name }}"; + option routers {{ network.gateway }}; + default-lease-time 86400; + max-lease-time 86400; +{% if network.range_start is defined %} + range {{ network.range_start }} {{ network.range_end }}; +{% endif %} + +{% for host in network.hosts %} + host {{ host.name }} { hardware ethernet {{ host.mac }}; fixed-address {{ network.network_prefix }}.{{ host.ip }}; } +{% if host.mac2 is defined %} + host {{ host.name }}_2 { hardware ethernet {{ host.mac2 }}; fixed-address {{ network.network_prefix }}.{{ host.ip }}; } +{% endif %} +{% endfor %} +} diff --git a/roles/dns/vars/main.yml b/roles/network/vars/main.yml similarity index 62% rename from roles/dns/vars/main.yml rename to roles/network/vars/main.yml index 4ab03b5..0cbdbb5 100644 --- a/roles/dns/vars/main.yml +++ b/roles/network/vars/main.yml @@ -1,55 +1,52 @@ --- lan: - network: 192.168.50 + network_prefix: 192.168.50 + network_name: lan + address: 192.168.50.0 + mask: 255.255.255.0 + gateway: 192.168.50.2 + dns: 192.168.50.100 + range_start: 192.168.50.200 + range_end: 192.168.50.250 hosts: - name: router ip: 2 + mac: 2c:b0:5d:4a:72:62 - name: bender ip: 3 - - name: openhab + mac: e0:3f:49:6f:03:c2 + - name: prusa-new + ip: 4 + mac: b8:27:eb:96:f3:3f + mac2: b8:27:eb:c3:a6:6a + - name: home-assistant ip: 5 - - name: access-point - ip: 6 + mac: dc:a6:32:8b:7b:ab + mac2: 6a:1b:c8:63:58:7a - name: iron-man ip: 7 + mac: dc:a6:32:03:6d:fa - name: prusa ip: 8 + mac: b8:27:eb:ff:2a:86 - name: farnsworth ip: 21 - - name: groot - ip: 22 - - name: xbox - ip: 31 - - name: wii - ip: 32 - - name: ps3 - ip: 33 - - name: ps4 - ip: 34 - - name: vita - ip: 35 - - name: switch - ip: 36 + mac: e0:3f:49:83:e8:dd - name: ipad ip: 46 + mac: b8:63:4d:b6:4c:bc - name: android-sgs9 ip: 47 - - name: tv - ip: 50 - - name: soundbar - ip: 51 - - name: shield - ip: 52 - - name: printer - ip: 64 - - name: kindle - ip: 70 + mac: 24:18:1d:bc:fe:4f - name: node-01 ip: 101 + mac: dc:a6:32:03:6d:fa - name: node-02 ip: 102 + mac: dc:a6:32:3c:0f:ff - name: node-03 ip: 103 + mac: dc:a6:32:3c:1a:ec iot: network: 192.168.60 hosts: @@ -86,6 +83,12 @@ iot: - name: router-power-outlet ip: 14 mac: cc:32:e5:69:7a:da + - name: tv + ip: 15 + mac: c0:48:e6:1f:ca:a7 + - name: soundbar + ip: 16 + mac: cc:6e:a4:2a:06:4e - name: camera-livingroom ip: 20 mac: 78:11:dc:7b:4d:04 @@ -102,17 +105,40 @@ equipment: hosts: - name: nvidia-shield ip: 10 +# ip: 11 mac: 00:04:4b:cd:a6:5b - - name: nvidia-shield-wifi + mac2: 00:04:4b:cd:a6:59 + - name: kindle ip: 11 - mac: 00:04:4b:cd:a6:59 - - name: ps4 - ip: 12 - mac: 00:d9:d1:76:7b:c5 - - name: nintendo-switch-wifi - ip: 15 - mac: 64:b5:c6:6f:ff:a8 + mac: 68:54:FD:BB:06:61 - name: printer ip: 17 mac: 38:9d:92:d0:6d:8e + - name: wii + ip: 21 + mac: 00:1e:35:e7:b3:a0 + - name: xbox + ip: 22 + mac: 7c:ed:8d:0f:c6:63 + - name: ps3 + ip: 23 + mac: 00:1d:0d:c2:07:b0 + - name: ps-vita + ip: 34 + mac: 00:d9:d1:4f:8f:91 + - name: ps4 + ip: 25 + mac: 00:d9:d1:76:7b:c5 + - name: nintendo-switch + ip: 26 + mac: 64:b5:c6:6f:ff:a8 +management: + network: 192.168.1 + hosts: + - name: router + ip: 1 + - name: switch + ip: 2 + - name: access-point + ip: 3 \ No newline at end of file