|
| 1 | +--- |
| 2 | +- name: match interface sections |
| 3 | + pattern_match: |
| 4 | + regex: "^\\S+ is (up|down)" |
| 5 | + match_all: yes |
| 6 | + match_greedy: yes |
| 7 | + register: context |
| 8 | + |
| 9 | +- name: match interface values |
| 10 | + pattern_group: |
| 11 | + - name: match name |
| 12 | + pattern_match: |
| 13 | + regex: "^(.+) is (\\w+)" |
| 14 | + content: "{{ item }}" |
| 15 | + register: name |
| 16 | + |
| 17 | + - name: match admin state |
| 18 | + pattern_match: |
| 19 | + regex: "admin state is (\\S+)" |
| 20 | + content: "{{ item }}" |
| 21 | + register: admin_state |
| 22 | + |
| 23 | + - name: match mac address |
| 24 | + pattern_match: |
| 25 | + regex: "Hardware: Ethernet, address: ([\\d|\\w]{4}.[\\d|\\w]{4}.[\\d|\\w]{4})" |
| 26 | + content: "{{ item }}" |
| 27 | + register: mac_addr |
| 28 | + |
| 29 | + - name: match description value |
| 30 | + pattern_match: |
| 31 | + regex: "Description: (.*)" |
| 32 | + content: "{{ item }}" |
| 33 | + register: description |
| 34 | + |
| 35 | + - name: match mtu value |
| 36 | + pattern_match: |
| 37 | + regex: "MTU (\\d+)" |
| 38 | + content: "{{ item }}" |
| 39 | + register: mtu |
| 40 | + |
| 41 | + - name: match ipv4 address |
| 42 | + pattern_match: |
| 43 | + regex: "Internet Address is (.+)" |
| 44 | + content: "{{ item }}" |
| 45 | + register: ipv4addr |
| 46 | + |
| 47 | + - name: match port mode |
| 48 | + pattern_match: |
| 49 | + regex: "Port mode is (.+)" |
| 50 | + content: "{{ item }}" |
| 51 | + register: port_mode |
| 52 | + |
| 53 | + loop: "{{ context }}" |
| 54 | + register: values |
| 55 | + |
| 56 | +- name: build interface template |
| 57 | + json_template: |
| 58 | + template: |
| 59 | + - key: "{{ item.name.matches.0 }}" |
| 60 | + object: |
| 61 | + - key: oper_status |
| 62 | + value: "{{ item.name.matches.1 }}" |
| 63 | + - key: admin_status |
| 64 | + value: "{{ item.admin_state.matches.0}}" |
| 65 | + - key: mac_address |
| 66 | + value: "{{ item.mac_addr.matches.0 }}" |
| 67 | + - key: ipv4 |
| 68 | + object: |
| 69 | + - key: address |
| 70 | + value: "{{ item.ipv4addr.matches.0.split('/')[0] }}" |
| 71 | + - key: masklen |
| 72 | + value: "{{ item.ipv4addr.matches.0.split('/')[1] }}" |
| 73 | + when: item.ipv4addr.matches |
| 74 | + - key: description |
| 75 | + value: "{{ item.description.matches.0 }}" |
| 76 | + - key: mtu |
| 77 | + value: "{{ item.mtu.matches.0 }}" |
| 78 | + - key: port_mode |
| 79 | + value: "{{ item.port_mode.matches.0}}" |
| 80 | + loop: "{{ values }}" |
| 81 | + register: interfaces |
| 82 | + export: yes |
| 83 | + export_as: dict |
| 84 | + extend: cisco_nxos |
0 commit comments