Json parsing in Ansible : <p>I have to parse the output of the following command:</p>

<pre><code>mongo &lt;dbname&gt; --eval "db.isMaster()"
</code></pre>

<p>which gives output as follows:</p>

<pre><code> {
    "hosts" : [
        "xxx:&lt;port&gt;",
        "xxx:&lt;port&gt;",
        "xxx:&lt;port&gt;"
    ],
    "setName" : "xxx",
    "setVersion" : xxx,
    "ismaster" : true,
    "secondary" : false,
    "primary" : "xxx",
    "me" : "xxx",
    "electionId" : ObjectId("xxxx"),
    "maxBsonObjectSize" : xxx,
    "maxMessageSizeBytes" : xxxx,
    "maxWriteBatchSize" : xxx,
    "localTime" : ISODate("xxx"),
    "maxWireVersion" : 4,
    "minWireVersion" : 0,
    "ok" : 1
}
</code></pre>

<p>I need to parse the above output to check the value of "ismaster" is true. Please let me know how i can do this in ansible.</p>

<p>At the moment i am simply checking that the text "ismaster" : true is shown in the output using the following code:</p>

<pre><code>  tasks:
     - name: Check if the mongo node is primary
       shell: mongo &lt;dbname&gt; --eval "db.isMaster()"
       register: output_text

     - name: Run command on master
       shell: &lt;command to execute&gt;
       when: "'\"ismaster\\\" : true,' in output_text.stdout"
</code></pre>

<p>However it would be nice to use Ansible's json processing to check the same. Please advise.</p>
