Compare commits
	
		
			5 Commits
		
	
	
		
			9eb580b841
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c281a13b8e | |||
| 0b871998aa | |||
| 6117f168aa | |||
| ac7cb1bc44 | |||
| eae8ce0848 | 
@@ -1,6 +1,7 @@
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
# defaults file for network-manager
 | 
					# defaults file for network-manager
 | 
				
			||||||
nm_version: =1.42.*
 | 
					nm_version: =1.42.*
 | 
				
			||||||
 | 
					nm__skip_install: false
 | 
				
			||||||
# force to configure conf.d/10-globally-managed-devices.conf
 | 
					# force to configure conf.d/10-globally-managed-devices.conf
 | 
				
			||||||
globally_managed_devices: true
 | 
					globally_managed_devices: true
 | 
				
			||||||
globally_managed_devices_path: "/etc/NetworkManager/conf.d/10-globally-managed-devices.conf"
 | 
					globally_managed_devices_path: "/etc/NetworkManager/conf.d/10-globally-managed-devices.conf"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,13 @@
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
# handlers file for systemd-timesyncd
 | 
					# handlers file for network-manager
 | 
				
			||||||
- name: restart network-manager
 | 
					- name: Restart NetworkManager
 | 
				
			||||||
  become: true
 | 
					  systemd:
 | 
				
			||||||
  service:
 | 
					    name: NetworkManager
 | 
				
			||||||
    name: NetworkManager.service
 | 
					 | 
				
			||||||
    state: restarted
 | 
					    state: restarted
 | 
				
			||||||
  listen: network-manager configuration changed
 | 
					
 | 
				
			||||||
 | 
					- name: Reboot the system
 | 
				
			||||||
 | 
					  reboot:
 | 
				
			||||||
 | 
					    reboot_timeout: 180
 | 
				
			||||||
 | 
					  async: 0
 | 
				
			||||||
 | 
					  poll: 0
 | 
				
			||||||
 | 
					  listen: "Notify the reboot handler"
 | 
				
			||||||
							
								
								
									
										34
									
								
								tasks/check_udev_rules.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								tasks/check_udev_rules.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: Check and remove udev rules
 | 
				
			||||||
 | 
					  block:
 | 
				
			||||||
 | 
					    - name: Find udev rules files
 | 
				
			||||||
 | 
					      find:
 | 
				
			||||||
 | 
					        paths: /etc/udev/rules.d
 | 
				
			||||||
 | 
					        patterns: "*-cloud-ifupdown.rules"
 | 
				
			||||||
 | 
					      register: udev_rules_to_remove
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    - name: Get dynamically defined file path from udev rule
 | 
				
			||||||
 | 
					      command: grep -oP 'RUN\+="\K[^"]*' "{{ run.path }}"
 | 
				
			||||||
 | 
					      with_items: "{{ udev_rules_to_remove.files }}"
 | 
				
			||||||
 | 
					      register: dynamic_file_paths
 | 
				
			||||||
 | 
					      loop_control:
 | 
				
			||||||
 | 
					        loop_var: run
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    - name: Remove dynamically defined file
 | 
				
			||||||
 | 
					      file:
 | 
				
			||||||
 | 
					        path: "{{ runf.stdout }}"
 | 
				
			||||||
 | 
					        state: absent
 | 
				
			||||||
 | 
					      with_items: "{{ dynamic_file_paths.results }}"
 | 
				
			||||||
 | 
					      when: runf.stdout is defined and runf.stdout != ''
 | 
				
			||||||
 | 
					      loop_control:
 | 
				
			||||||
 | 
					        loop_var: runfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    - name: Remove udev rules
 | 
				
			||||||
 | 
					      file:
 | 
				
			||||||
 | 
					        path: "{{ rule.path }}"
 | 
				
			||||||
 | 
					        state: absent
 | 
				
			||||||
 | 
					      with_items: "{{ udev_rules_to_remove.files | default([]) }}"
 | 
				
			||||||
 | 
					      when: udev_rules_to_remove.matched > 0
 | 
				
			||||||
 | 
					      loop_control:
 | 
				
			||||||
 | 
					        loop_var: rule
 | 
				
			||||||
 | 
					      notify: Notify the reboot handler
 | 
				
			||||||
@@ -1,16 +1,20 @@
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
# tasks file for network-manager
 | 
					# tasks file for network-manager
 | 
				
			||||||
 | 
					 | 
				
			||||||
- name: "apt install NetworkManager {{ nm_version }} "
 | 
					- name: "apt install NetworkManager {{ nm_version }} "
 | 
				
			||||||
  become: true
 | 
					  when: nm__skip_install is not true
 | 
				
			||||||
  apt:
 | 
					  apt:
 | 
				
			||||||
    name: "network-manager{{ nm_version }}"
 | 
					    name: "network-manager{{ nm_version }}"
 | 
				
			||||||
    default_release: "{{ ansible_distribution_release }}-backports"
 | 
					    default_release: "{{ ansible_distribution_release }}-backports"
 | 
				
			||||||
    autoremove: true
 | 
					    autoremove: true
 | 
				
			||||||
    update_cache: true
 | 
					    update_cache: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Enable service NetworkManager and ensure it is not masked
 | 
				
			||||||
 | 
					  ansible.builtin.systemd_service:
 | 
				
			||||||
 | 
					    name: NetworkManager
 | 
				
			||||||
 | 
					    enabled: true
 | 
				
			||||||
 | 
					    masked: no
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: config globally managed devices
 | 
					- name: config globally managed devices
 | 
				
			||||||
  become: true
 | 
					 | 
				
			||||||
  template:
 | 
					  template:
 | 
				
			||||||
    src: "conf.d/10-globally-managed-devices.j2"
 | 
					    src: "conf.d/10-globally-managed-devices.j2"
 | 
				
			||||||
    dest: "{{ globally_managed_devices_path }}"
 | 
					    dest: "{{ globally_managed_devices_path }}"
 | 
				
			||||||
@@ -18,27 +22,53 @@
 | 
				
			|||||||
    group: root
 | 
					    group: root
 | 
				
			||||||
    mode: 0644
 | 
					    mode: 0644
 | 
				
			||||||
  when: globally_managed_devices is true
 | 
					  when: globally_managed_devices is true
 | 
				
			||||||
  notify: network-manager configuration changed
 | 
					  notify: Restart NetworkManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: cleanup globally managed devices
 | 
					- name: cleanup globally managed devices
 | 
				
			||||||
  become: true
 | 
					 | 
				
			||||||
  file:
 | 
					  file:
 | 
				
			||||||
    path: "{{ globally_managed_devices_path }}"
 | 
					    path: "{{ globally_managed_devices_path }}"
 | 
				
			||||||
    state: absent
 | 
					    state: absent
 | 
				
			||||||
  when: not globally_managed_devices
 | 
					  when: not globally_managed_devices
 | 
				
			||||||
 | 
					  notify: Restart NetworkManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Configure NetworkManager
 | 
					- name: Include tasks for checking and removing udev rules
 | 
				
			||||||
  become: true
 | 
					  include_tasks: check_udev_rules.yml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Configure NetworkManager [ type loopback ]
 | 
				
			||||||
  community.general.nmcli:
 | 
					  community.general.nmcli:
 | 
				
			||||||
    conn_name: "{{ net_item.con_name }}"
 | 
					    autoconnect: "{{ connection.autoconnect | default('true') }}"
 | 
				
			||||||
    ifname: "{{ net_item.ifname }}"
 | 
					    conn_name: "{{ connection.con_name | default('lo') }}"
 | 
				
			||||||
    type: "{{ net_item.type }}"
 | 
					    ifname: "{{ connection.ifname | default('lo') }}"
 | 
				
			||||||
    ip4: "{{ net_item.ip4 }}"
 | 
					    type: "{{ connection.type }}"
 | 
				
			||||||
    gw4: "{{ net_item.gw4 | default('') }}"
 | 
					    ip4: "{{ connection.ip4 | default('') }}"
 | 
				
			||||||
    dns4: "{{ net_item.dns4 | default([]) }}"
 | 
					    dns4: "{{ connection.dns4 | default([]) }}"
 | 
				
			||||||
    method6: "{{ net_item.method6 | default('auto') }}"
 | 
					    method4: "{{ connection.method4 | default('manual') }}"
 | 
				
			||||||
 | 
					    method6: "{{ connection.method6 | default('auto') }}"
 | 
				
			||||||
    state: present
 | 
					    state: present
 | 
				
			||||||
  with_items: "{{ network }}"
 | 
					  with_items: "{{ network }}"
 | 
				
			||||||
 | 
					  when: connection.type == 'loopback'
 | 
				
			||||||
  loop_control:
 | 
					  loop_control:
 | 
				
			||||||
    loop_var: net_item
 | 
					    loop_var: connection
 | 
				
			||||||
  notify: network-manager configuration changed
 | 
					  notify: Restart NetworkManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Configure NetworkManager [ type ethernet ]
 | 
				
			||||||
 | 
					  community.general.nmcli:
 | 
				
			||||||
 | 
					    autoconnect: "{{ connection.autoconnect | default('true') }}"
 | 
				
			||||||
 | 
					    conn_name: "{{ connection.con_name }}"
 | 
				
			||||||
 | 
					    ifname: "{{ connection.ifname }}"
 | 
				
			||||||
 | 
					    type: "{{ connection.type }}"
 | 
				
			||||||
 | 
					    ip4: "{{ connection.ip4 | default('') }}"
 | 
				
			||||||
 | 
					    gw4: "{{ connection.gw4 | default('') }}"
 | 
				
			||||||
 | 
					    dns4: "{{ connection.dns4 | default([]) }}"
 | 
				
			||||||
 | 
					    routes4: "{{ connection.routes4 | default([]) }}"
 | 
				
			||||||
 | 
					    method4: "{{ connection.method4 | default('manual') }}"
 | 
				
			||||||
 | 
					    method6: "{{ connection.method6 | default('disabled') }}"
 | 
				
			||||||
 | 
					    state: present
 | 
				
			||||||
 | 
					  with_items: "{{ network }}"
 | 
				
			||||||
 | 
					  when: connection.type == 'ethernet'
 | 
				
			||||||
 | 
					  loop_control:
 | 
				
			||||||
 | 
					    loop_var: connection
 | 
				
			||||||
 | 
					  notify: Restart NetworkManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Notify the reboot handler
 | 
				
			||||||
 | 
					  meta: flush_handlers
 | 
				
			||||||
		Reference in New Issue
	
	Block a user