This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
homeserver-ansible/roles/networking/connection/tasks/main.yml

71 lines
1.5 KiB
YAML
Raw Normal View History

2022-03-01 17:43:44 -05:00
- name: Install packages
2022-02-27 16:05:34 -05:00
community.general.pacman:
name:
- networkmanager
- name: Enable NetworkManager
service:
name: NetworkManager
enabled: yes
state: started
2022-03-02 19:58:31 -05:00
- name: Send script to remove externally managed eth0 connection
template:
src: rmconn.sh
dest: /root/rmconn.sh
mode: 700
register: rmconn
- 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
2022-02-27 16:05:34 -05:00
2022-03-02 19:58:31 -05:00
- 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: Create NetworkManager connection
2022-02-27 16:05:34 -05:00
community.general.nmcli:
dns4: "{{ local_ip }}"
2022-02-27 16:05:34 -05:00
dns4_ignore_auto: yes
2022-03-04 07:30:09 -05:00
ip4: "{{ local_ip }}{{ subnet_prefix }}"
2022-03-06 19:36:53 -05:00
gw4: "{{ gateway }}"
2022-02-27 16:05:34 -05:00
method4: manual
state: present
conn_name: wired
ifname: "{{ interface }}"
type: ethernet
2022-03-02 19:58:31 -05:00
register: nmcli_conf
changed_when: false
2022-03-02 19:58:31 -05:00
poll: 0
async: 1000
- name: Set ansible_host to static IP
set_fact:
ansible_host: "{{ local_ip }}"
- name: Reconnect to new IP
wait_for_connection:
timeout: 240
2022-03-01 17:43:44 -05:00
2022-03-02 19:58:31 -05:00
when: nmcli_conf.changed
- name: Remove rmconn task at every minute
2022-03-01 17:43:44 -05:00
cron:
2022-03-02 19:58:31 -05:00
name: "Ensure eth0 is not externally managed (temporary)"
state: absent