Ansible on IOS to loop through subset of interfaces

Running WISL on Windows 10 and Ubuntu with ansible 2.9.9. I am new to Ansible. I execute a show on a Cisco device to yield the interfaces on which a given network protocol runs. I then want to extract the interfaces and execute commands on them. In this case to turn off the protocol. Ideally the show command could change easily. As for many protocols this is the consistent way I would check this state. There may be ways Ansible stores this protocol information. Maybe with facts? I found examples using ios_config at but the interfaces are hard coded as shown here with the helper example:

- name: configure ip helpers on multiple interfaces
      - ip helper-address
      - ip helper-address
    parents: "{{ item }}"
    - interface Ethernet1
    - interface Ethernet2
    - interface GigabitEthernet1

My attempt is as follows which gives me the two interfaces with multicast active. But what next to act on those interfaces in a loop? :

  - name: Gather interfaces running PIM
        - show ip pim interface
    register: pim

  - name: Write PIM interface data to file
      content: "{{pim.stdout_lines[0]}}"
      dest: "backups/{{ansible_alias}}-pim-interfaces.txt"

  - name: Glean PIM INTF's
    shell: cat backups/{{ ansible_alias }}-pim-interfaces.txt | tr ' ' 'n' | grep 'GigabitEthernet'
    register: pim

  - debug: msg='{{ pim.stdout_lines }}'

TASK [debug] ******************************************************************************************************************************************************************************************************
ok: [] => {
    "msg": [

Many thanks for any guidance.

Go to Source
Author: IainT