---
# connman itself is already installed in the parent task
- name: networking | Install connman packages
  community.general.apk:
    name: connman-nftables, connman-resolvconf
    state: present

- name: networking | Copy connman configuration
  copy:
    src: networking/connman/main.conf
    dest: /etc/connman/main.conf
    owner: root
    group: root
    mode: '644'

- name: networking | Make sure /var/lib/connman directory exists
  file:
    path: /var/lib/connman
    mode: '755'
    owner: root
    group: root
    state: directory

- name: networking | Configure connman Ethernet interfaces
  template:
    src: networking/connman-service.config.j2
    dest: /var/lib/connman/ethernet_services.config
    owner: root
    group: root
    mode: '644'

- name: networking | Copy connmand service configuration
  copy:
    src: networking/connman/connman.confd
    dest: /etc/conf.d/connman
    owner: root
    group: root
    mode: '644'

- name: networking | Start connman services on runlevel 'default'
  service:
    name: '{{ item }}'
    runlevel: default
    enabled: true
  loop:
    - connman
    - connman-resolvconf
