I'm trying to extract a specific number from my stdout_lines in Ansible and use that as a variable. I'm running a show command in my playbook and all I want to get from the output is the highest sequence number from my crypto map. For example this is my playbook:
-
asa_command:
commands:
- show run crypto map
provider: "{{ base_provider }}"
register: result
-
debug: var=result.stdout_lines
This produces the output fine but I'm not sure how to go about extracting the sequence number from the following (I have omitted most of the crypto map just to make it easier to explain).
"crypto map map1 60 set ikev1 transform-set test",
"crypto map map1 60 set security-association lifetime seconds 3600",
"crypto map map1 61 set peer 1.1.1.1 ",
"crypto map map1 61 set ikev1 transform-set test1",
"crypto map map1 61 set security-association lifetime seconds 3600",
"crypto map map1 interface outside"
So basically, I would like to extract the highest sequence number (in this case "61") so I can input it as a variable in the same playbook. Any thoughts would be appreciated :-)
I tried looking at some jinja2 filters but I couldn't figure out what would be most appropriate for my usage.
http://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_filters.html
I also tried the suggestions on this page but I didn't get far with that either.