Ansible Tasks to Configure Network Manager on Ubuntu 22

Here are the steps I am using to configure Network Manager on Ubuntu 22 systems.

- name: configure network manager for debian
  block:

    - name: ensure network manager is installed - debian
      apt:
        name: network-manager
        state: present

    - name: get list of files in /etc/netplan
      find:
        path: "/etc/netplan/"
      register: cleanup
      ignore_errors: true

    - name: remove all files in /etc/netplan
      file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ cleanup.files }}"
      ignore_errors: true

    - name: touch network manager config
      command: touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf

    - name: restart network manager service
      service:
        name: NetworkManager
        state: restarted

    - name: netplan apply
      command: netplan apply

    - name: added default device as managed by network manager
      command: "nmcli device set {{ ansible_default_ipv4.interface }} managed yes"


  when: ansible_os_family == 'Debian'

You may also like...