- name: Install packages community.general.pacman: name: - networkmanager - name: Disable MAC randomization template: src: mac-randomization.conf.j2 dest: /etc/systemd/resolved.conf.d/30-mac-randomization.conf - name: Enable NetworkManager service: name: NetworkManager enabled: yes state: started - name: Send script to remove externally managed eth0 connection template: src: rmconn.sh dest: /root/rmconn.sh mode: 700 register: rmconn - name: Disable DHCP DNS template: src: nodns.network.j2 dest: /etc/systemd/network/50-nodns.network - name: Create resolved configuration directory file: path: /etc/systemd/resolved.conf.d state: directory - name: Set DNS template: src: dns_servers.conf.j2 dest: /etc/systemd/resolved.conf.d/50-dns_servers.conf register: set_dns - name: Restart resolved systemd: name: systemd-resolved state: restarted when: set_dns.changed - name: Create NetworkManager connection community.general.nmcli: dns4: "{{ nameserver }}" dns4_ignore_auto: yes ip4: "{{ local_ip }}{{ subnet_prefix }}" gw4: "{{ gateway }}" method4: manual state: present conn_name: "{{ conn_name }}" ssid: "{{ conn_ssid }}" wifi_sec: key-mgmt: wpa-psk psk: "{{ conn_pass }}" ifname: "{{ net_interface }}" type: "{{ conn_type }}" register: nmcli_conf changed_when: false poll: 0 async: 1000 - name: Run rmconn every 30 minutes cron: name: "Ensure eth0 is not externally managed" minute: "*/30" job: "/root/rmconn.sh" state: present - name: Run rmconn every minute (temporarily) cron: name: "Ensure eth0 is not externally managed (temporary)" minute: "*" job: "/root/rmconn.sh" state: present when: rmconn.changed - name: Run rmconn at boot cron: name: "Ensure eth0 is not externally managed (at reboot)" special_time: reboot job: "/root/rmconn.sh" state: present - name: Reset Ansible connection params set_fact: ansible_host: "{{ local_ip }}" when: nmcli_conf.changed or rmconn.changed - name: Attempt to reconnect wait_for_connection: timeout: 240 when: nmcli_conf.changed or rmconn.changed - name: Remove rmconn task at every minute cron: name: "Ensure eth0 is not externally managed (temporary)" state: absent