---
- name: Setup data as facts
  ansible.builtin.set_fact:
    data:
      - interface_name: eth0
        enabled: true
        duplex: auto
        speed: auto
      - interface_name: eth1
        description: Configured by Ansible - Interface 1
        mtu: 1500
        speed: auto
        duplex: auto
        is_enabled: true
        vifs:
          - vlan_id: 100
            description: Eth1 - VIF 100
            mtu: 400
            is_enabled: true
          - vlan_id: 101
            description: Eth1 - VIF 101
            is_enabled: true
      - interface_name: eth2
        description: Configured by Ansible - Interface 2 (ADMIN DOWN)
        mtu: 600
        is_enabled: false

- name: Debug
  ansible.builtin.debug:
    msg: "{{ data | ansible.utils.keep_keys(target=['desc', 'interface_'], matching_parameter='starts_with') }}"
  register: result

- name: Assert result dicts
  ansible.builtin.assert:
    that:
      - keep['starts_with'] == result['msg']

- name: Setup data as facts for equivalent
  ansible.builtin.set_fact:
    data:
      - interface_name: eth0
        enabled: true
        duplex: auto
        speed: auto
      - interface_name: eth1
        description: Configured by Ansible - Interface 1
        mtu: 1500
        speed: auto
        duplex: auto
        is_enabled: true
        vifs:
          - vlan_id: 100
            description: Eth1 - VIF 100
            mtu: 400
            is_enabled: true
          - vlan_id: 101
            description: Eth1 - VIF 101
            is_enabled: true
      - interface_name: eth2
        description: Configured by Ansible - Interface 2 (ADMIN DOWN)
        mtu: 600
        is_enabled: false

- name: Debug
  ansible.builtin.debug:
    msg: "{{ data | ansible.utils.keep_keys(target=['interface_name', 'is_enabled', 'vlan_id']) }}"
  register: result

- name: Assert result dicts
  ansible.builtin.assert:
    that:
      - keep_default['default'] == result['msg']
