title: Extract substring from variable in Ansible
body: <p>Edited:
  I wrote this playbook but it does not show the extracted variable:</p>
  
  <pre><code>---
  - hosts: fppc
    gather_facts: false
    remote_user: xyz  
    connection: local
    tasks:
    - name: N1
      ios_command:
         commands:
           - sh run | i bann          
      register: sr
  
    - debug: msg="{{ sr.stdout}}"
  
    - set_fact: 
        rid: "{{ sr.stdout | regex_search('.*ID: (..)')  }}"
  
    - debug: msg="{{ rid }}"
  </code></pre>
  
  <p>Execution:</p>
  
  <pre><code>ansible@Ansible:~$ ansible-playbook pb1.yml
  
  PLAY [fppc] *************************************************************************
  
  TASK [N1] ***************************************************************************
  ok: [192.168.250.161]
  
  TASK [debug] ************************************************************************
  ok: [192.168.250.161] =&gt; {
      "msg": [
          "banner login ^CID: A4"
      ]
  }
  
  TASK [set_fact] *********************************************************************
  fatal: [192.168.250.161]: FAILED! =&gt; {"failed": true, "msg": "Unexpected templating type error occurred on ({{ sr.stdout | regex_search('.*ID: (..)')  }}): expected string or buffer"}
          to retry, use: --limit @/home/ansible/pb1.retry
  
  PLAY RECAP **************************************************************************
  192.168.250.161            : ok=2    changed=0    unreachable=0    failed=1   
  
  ansible@Ansible:~$
  </code></pre>