Initial commit

This commit is contained in:
2024-10-30 01:50:38 +01:00
commit 587ca23374
147 changed files with 7521 additions and 0 deletions

101
addNewAPs.yml Normal file
View File

@@ -0,0 +1,101 @@
- name: Detekce zařízení v síti
hosts: localhost
vars:
subnets: ["10.11.99", "10.22.99"]
gather_facts: no
tasks:
- name: Získání seznamu zařízení v rozsahu DHCP serveru
ansible.builtin.shell: |
for i in $(seq 100 254); do
ping -W .1 -c 1 {{ item }}.$i > /dev/null 2>&1 && echo {{ item }}.$i;
done || true
register: new_ips
loop: "{{ subnets }}"
- name: Přidat aktivní IP do dynamického inventáře
ansible.builtin.add_host:
name: "{{ item }}"
groups: found_devices
loop: "{{ new_ips.results | map(attribute='stdout_lines') | flatten }}"
- name: Přidat skupinu found_devices do metaskupiny openwrt
ansible.builtin.add_host:
groups: openwrt
name: "{{ item }}"
loop: "{{ groups['found_devices'] }}"
- name: Získání seznamu volných adres mimo DHCP server
ansible.builtin.shell: |
for i in $(seq 1 99); do
ping -W .1 -c 1 {{ item }}.$i > /dev/null 2>&1 || echo {{ item }}.$i;
done
register: free_ips
loop: "{{ subnets }}"
- name: Vytvoření seznamu volných IP adres podle subnetu
set_fact:
free_subnet_ips: "{{ free_subnet_ips | default({}) | combine({item.item: item.stdout_lines}) }}"
loop: "{{ free_ips.results }}"
- name: Získání hostů a generování hostnamů
hosts: found_devices
roles:
- gekmihesg.openwrt
gather_facts: yes
vars:
ansible_scp_extra_args: "-O"
openwrt_install_recommended_packages: false
tasks:
- name: Získání unikátního názvu zařízení podle MAC adresy
set_fact:
hostname: "ap_{{ ansible_facts.openwrt_devices[ansible_facts.openwrt_interfaces.mgmnt.l3_device].macaddr.replace(':', '') }}"
- name: Uložení ip adresy hosta a hosnamu do seznamu hostů
set_fact:
host_info: { "ip": "{{ ansible_host }}", "hostname": "{{ hostname }}" }
- name: Shromáždění informací o všech hostech a předání na localhost
delegate_to: localhost
delegate_facts: true
run_once: true
set_fact:
found_hosts_info: "{{ ansible_play_hosts | map('extract', hostvars, 'host_info') | list }}"
- name: Přidání nového access poitu do správy
hosts: localhost
gather_facts: no
tasks:
- name: Přidělení statické IP adresy a vytvoření souboru v host_vars
include_tasks: include/createHostVars.yml
loop: "{{ found_hosts_info }}"
- meta: refresh_inventory
- name: Přidat nalezených hostů do dynamického inventáře
ansible.builtin.add_host:
name: '{{ item.hostname }}'
ansible_host: '{{ item.ip }}'
groups: new_devices
loop: "{{ found_hosts_info }}"
- name: Přidat skupinu new_devices do metaskupiny openwrt
ansible.builtin.add_host:
groups: openwrt
name: "{{ item }}"
loop: "{{ groups['new_devices'] }}"
- name: Nastavení statické ip na mgmnt interface
hosts: new_devices
roles:
- gekmihesg.openwrt
- network
gather_facts: yes
vars:
ansible_scp_extra_args: "-O"
device_bridge_port: "{{ ansible_facts.openwrt_interfaces.mgmnt.device | regex_search('eth[0-9]+|wan') }}"
network_interfaces:
- id: "mgmnt"
proto: "static"
device: "{{ device_bridge_port }}.99"
ipaddr: "{{ device_ip_address }}/24"
gateway: "{{ device_ip_address | regex_replace('\\.[0-9]+$', '.1') }}"
dns: ["{{ device_ip_address | regex_replace('\\.[0-9]+$', '.1') }}"]
pre_tasks:
- name: update time
command:
cmd: ntpd -dnq -p pool.ntp.org
changed_when: false