title: Extract values from stdout output using Ansible
body: <p>I am running a command to get the status of tomcat and registering it in a variable. How do i extract the specific output of that command and put it in a variable to check further </p>
  
  <p>Play -</p>
  
  <pre><code>- name: Check the State og tomcat service
     shell: "svcs tomcat"
     register: tomcat_status
  
   - name: Show captured processes
     debug:
       msg: "{{ tomcat_status.stdout_lines|list }}"
  </code></pre>
  
  <p>The output of the above is -</p>
  
  <pre><code> server1 ok: {
      "changed": false,
      "msg": [
          "STATE          STIME    FMRI",
          "online         20:11:48 svc:/network/tomcat:tomcat"
      ]
  }
  </code></pre>
  
  <p>How do i extract the value of STATE here? I want to know if it's online or disabled or shutdown etc.</p>
  
  <p>NOTE - Output with -vvvv</p>
  
  <pre><code> server1 done: {
      "changed": true,
      "cmd": "svcs tomcat",
      "delta": "0:00:00.025711",
      "end": "2020-05-11 12:43:43.323017",
      "invocation": {
          "module_args": {
              "_raw_params": "svcs tomcat",
              "_uses_shell": true,
              "argv": null,
              "chdir": null,
              "creates": null,
              "executable": null,
              "removes": null,
              "stdin": null,
              "stdin_add_newline": true,
              "strip_empty_ends": true,
              "warn": false
          }
      },
      "rc": 0,
      "start": "2020-05-11 12:43:43.297306",
      "stderr": "",
      "stderr_lines": [],
      "stdout": "STATE          STIME    FMRI\nonline         20:11:48 svc:/network/tomcat:tomcat",
      "stdout_lines": [
          "STATE          STIME    FMRI",
          "online         20:11:48 svc:/network/tomcat:tomcat"
      ]
  }
  </code></pre>