title: Extract data from stdout_lines in Ansible
body: <p>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:</p>
  
  <pre><code> - 
    asa_command:
        commands:
          -  show run crypto map
        provider: "{{ base_provider }}"
    register: result
  
  -
    debug: var=result.stdout_lines
  </code></pre>
  
  <p>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).</p>
  
  <pre><code>"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"
  </code></pre>
  
  <p>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 :-) </p>
  
  <p>I tried looking at some jinja2 filters but I couldn't figure out what would be most appropriate for my usage. </p>
  
  <p><a href="http://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_filters.html" rel="nofollow noreferrer">http://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_filters.html</a></p>
  
  <p>I also tried the suggestions on this page but I didn't get far with that either.</p>
  
  <p><a href="https://stackoverflow.com/questions/45740777/ansible-parse-text-string-from-stdout">ansible parse text string from stdout</a></p>