Gi0/1 connected 150 a-full a-1000 10/100/1000BaseTX
Gi0/2 connected trunk a-full a-1000 10/100/1000BaseTX
Gi0/3 notconnect 1 auto auto 10/100/1000BaseTX
Gi0/4 connected 150 a-full a-1000 10/100/1000BaseTX
Gi0/5 notconnect 1 auto auto 10/100/1000BaseTX
Gi0/6 notconnect 1 auto auto 10/100/1000BaseTX
Gi0/7 notconnect 1 auto auto 10/100/1000BaseTX
Gi0/8 notconnect 133 auto auto 10/100/1000BaseTX
Gi0/9 notconnect 1 auto auto Not Present
Gi0/10 notconnect 1 auto auto Not Present
Gi0/11
Fa0/1
Fa0/12
Is there any regular-expression that can capture only the interface-names (e.g. put them in different capture groups) to be able to use them in new tasks ?
CodePudding user response:
If running your ansible playbook on GNU/linux there may be some commands and options to make any subsequent regex-filtering obsolete.
What is the current command that produces this output?
See related questions:
- Get Linux network interface name with Ansible?
- ServerFault: How to enumerate network interfaces in Ansible
CodePudding user response:
Q: "Capture only the interface-names"
A: Given the data is text stored in the variable stdout, split the lines, select non-empty, split items, and select the first items
ifc: "{{ stdout.split('\n')|select()|map('split')|map('first') }}"
gives
ifc: [Gi0/1, Gi0/2, Gi0/3, Gi0/4, Gi0/5, Gi0/6, ... , Fa0/12]