<p>How do i convert the below kubectl command into ansible role/command to run on a cluster?</p>
<pre><code>kubectl get openshiftapiserver \
  -o=jsonpath='{range .items[0].status.conditions[?(@.type==&quot;Encrypted&quot;)]}{.reason}{&quot;\n&quot;}{.message}{&quot;\n&quot;}'
</code></pre>
<p>Below ansible playbook format doesn't seems to be correct one:</p>
<pre><code>- name: check apiserver
  command: kubectl get openshiftapiserver -o=jsonpath='{range .items[0].status.conditions[?(@.type==&quot;Encrypted&quot;)]}{.reason}{&quot;\n&quot;}{.message}{&quot;\n&quot;}'
</code></pre>

devops
<p>The task you've shown seems to do exactly what you want.  For example, consider the following playbook:</p>
<pre><code>- hosts: localhost
  tasks:
    - command: &gt;-
        kubectl get openshiftapiserver
        -o=jsonpath='{range .items[0].status.conditions[?(@.type==&quot;Encrypted&quot;)]}{.reason}{&quot;\n&quot;}{.message}{&quot;\n&quot;}'
      register: res

    - debug:
        var: res.stdout
</code></pre>
<p>If you run this, it produces the output:</p>
<pre><code>TASK [debug] **********************************************************************************
ok: [localhost] =&gt; {
    &quot;res.stdout&quot;: &quot;EncryptionDisabled\nEncryption is not enabled&quot;
}
</code></pre>
<p>That's the same output produced by running the <code>kubectl get ...</code> command manually from the command line.</p>
<hr />
<p>You could also parse the response in Ansible to generate slightly nicer output:</p>
<pre><code>- hosts: localhost
  tasks:
    - command: &gt;-
        kubectl get openshiftapiserver
          -o=jsonpath='{.items[0].status.conditions[?(@.type==&quot;Encrypted&quot;)]}'
      register: res

    - set_fact:
        encrypted: &quot;{{ res.stdout|from_json }}&quot;

    - debug:
        msg:
          - &quot;message: {{ encrypted.message }}&quot;
          - &quot;reason: {{ encrypted.reason }}&quot;
</code></pre>
<p>This would produce:</p>
<pre><code>TASK [debug] *********************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: [
        &quot;message: Encryption is not enabled&quot;,
        &quot;reason: EncryptionDisabled&quot;
    ]
}
</code></pre>
