Search code examples
ansibleraspbian

ansible nmcli for Raspbian 10


Using Ansible, I am trying to provision a Raspberry Pi just freshly imaged with Raspbian 10.

One of the tasks is to set up the network. I'm trying to use community.general.nmcli, but so far without success:

- hosts: all

  tasks:

    - name: update and upgrade apt packages
      become: true
      apt:
        upgrade: dist
        update_cache: true

    - name: Install network manager
      become: true
      apt:
        name: network-manager
        state: present

    # see https://gist.github.com/truh/de723a3bc0f837f75d3673ddf101e108 and
    # https://raspberrypi.stackexchange.com/a/73816/137489
    - name: Uninstall openresolv and dhcpcd5
      become: true
      apt:
        pkg:
        - openresolve
        - dhcpcd5
        state: absent
        purge: yes

    - name: configure network
      become: true
      community.general.nmcli:
        state: present
        conn_name: my-eth0
        ifname: eth0
        type: ethernet
        ip4: 192.168.1.2/24
        gw4: 192.168.1.1

The first three tasks correspond to:

sudo apt update
sudo apt install network-manager
sudo apt purge openresolv dhcpcd5

as recommended by this gist and this discussion.

These first 3 tasks allow me to use nmcli on the command line (of the RPi).

However, the fourth task (using community.general.nmcli) fails:

fatal: [192.168.1.2]: FAILED! => {"changed": false, "msg": "Error: invalid property 'routing-rules': 'routing-rules' not among [method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, route-table, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-timeout, dhcp-send-hostname, dhcp-hostname, dhcp-fqdn, never-default, may-fail, dad-timeout].\n", "name": "my-eth0", "rc": 2}

Is there a way to get Ansible's community.general.nmcli to work on Raspbian 10?


Solution

  • That is due to Raspbian using NetworkManager prior to version 1.18, which is when the functionality routing-rules was released. It wouldn't otherwise be a problem, however, Ansible nmcli module expects that this parameter is there when it attempts to create the interface, but then nmcli fails with this weird message.

    There's already an open issue for that: https://github.com/ansible-collections/community.general/issues/3948