ios_l2_interfaces vlan trunks

I am testing to loop a config to check all ports and add all vlans to the port. I am having an issue with the loop. I am wanting to loop through all interfaces that match the mode trunk

  • name: Add all vlans to trunks
    connection: network_cli
    gather_facts: no
    hosts: all
    vars:
    ansible_network_os: ios

tasks:

  • name: Configure L2 Trunks
    ios_l2_interfaces:
    mode: Trunk
    trunk_allowed_vlans: “{{ vlans | map(attribute=‘vlan_id’) | join(‘,’) }}”
    state: present
    loop: “{{ interfaces[inventory_hostname] | selectattr(‘mode’,‘equalto’,‘trunk’) | list }}”