0
- hosts: localhost
  gather_facts: no
  vars:
    output: |
         Routing entry for 2001:506:4200:4000::/50
              Known via "static", distance 1, metric 0 (connected)
              Installed Aug 12 12:39:44.252 for 8w6d
              Routing Descriptor Blocks
                directly connected, via Null0
                  Route metric is 0, Wt is 1
              No advertising protos.
  tasks:
    - set_fact:
        parse: "{{ output |  map('regex_replace', 'Routing entry for (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).*', 'Routing Entry: ')  }}"

Not sure what's happening in the regex replace function

If once an object matches I can work on other objects, any leads are appreciated

I'm looking to get the output in the below format :

{
  'Routing': '2001:506:4200:4000::/50',
  'Installed': 'Aug 12 12:39:44.252',
  'directly connected': 'via Null0',
  'Route metric': '0'
}
Nelson G.
  • 5,145
  • 4
  • 43
  • 54
Raghu
  • 43
  • 8
  • I think this is not good practice to do everything with Ansible 'code' or chaining filters, a playbook should be understandable by a normal person. This case can easily be addressed by developing a filter plugin, python offers more functions to manipulate strings. See – Nelson G. Oct 15 '20 at 07:23
  • you want this ? `parse: "{{ output | regex_replace('Routing entry for ', 'Routing Entry: ') }}"` – P.... Oct 15 '20 at 14:34
  • no luck, doesn't match anything – Raghu Oct 15 '20 at 16:27

0 Answers0