summaryrefslogtreecommitdiffstats
path: root/roles/network/tasks/main.yml
blob: 28a4b56d3d425b5eb452bf8b8c567274707ff647 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
- name: "Include OS-specific variables"
  ansible.builtin.include_vars: "{{ ansible_os_family | lower }}.yml"

- name: "Include OS-specific tasks"
  ansible.builtin.include_tasks: "install-{{ ansible_os_family | lower }}.yml"

- name: "Validate network_ipv4_* params"
  ansible.builtin.assert:
    that:
      - network_ipv4_address is defined
      - network_ipv4_gateway is defined
    fail_msg: "network_ipv4_address and network_ipv4_gateway are required together"
  when: network_ipv4_address is defined or network_ipv4_gateway is defined

- name: "(chroot): Ensure network_services are enabled"
  ansible.builtin.command:
    cmd: "systemctl enable {{ item }}"
  changed_when: true
  with_items: "{{ network_services }}"
  when: ansible_is_chroot
  # noqa: command-instead-of-module module doesn't work inside chroot

- name: "Configure NetworkManager"
  become: true
  notify:
    - "Reload systemd"
    - "Restart NetworkManager"
    - "Restart systemd-networkd"
    - "Restart systemd-resolved"
    - "Restart dhcpcd"
  block:
    - name: "Configure systemd-resolved"
      ansible.builtin.template:
        src: "resolved.conf.j2"
        dest: "/etc/systemd/resolved.conf"
        mode: "0644"

    - name: "Configure NetworkManager"
      ansible.builtin.template:
        src: "NetworkManager.conf.j2"
        dest: "/etc/NetworkManager/NetworkManager.conf"
        mode: "0644"

    - name: "Configure NetworkManager Captive Portals"
      ansible.builtin.get_url:
        dest: "/etc/NetworkManager/dispatcher.d/90-open_captive_portal"
        # yamllint disable-line
        url: "https://raw.githubusercontent.com/Seme4eg/captive-portal-sh/04751034437b6abd92647cab1b22cef586c86f4e/90-open_captive_portal"
        checksum: "sha1:75f4c827939e7dd433357ab4776c787be02c485b"
        mode: "0750"

    - name: "Configure ethernet connection"
      ansible.builtin.template:
        src: "eth0-connection.nmconnection.j2"
        dest: "/etc/NetworkManager/system-connections/ethernet.nmconnection"
        mode: "0600"
        owner: "root"
        group: "root"

    - name: "Configure wifi connection"
      ansible.builtin.template:
        src: "wifi-connection.nmconnection.j2"
        dest: "/etc/NetworkManager/system-connections/{{ network_wifi_ssid }}.nmconnection"
        mode: "0600"
        owner: "root"
        group: "root"
      when: network_wifi_ssid != ""