title: How to do command substitution over SSH in one line
body: <p>I need to check the uptime of a remote_server if its lesser than 600 sec, if its greater than it then print passed else print fail. I know its possible using HERE docs but I need to do this in one line . Following are two failed attempts using shell one liner and HERE doc</p>
  
  <p>Reason for using one line: I will feed the line to ansible's shell module. I tried following command and used single quotes to prevent expansion , but it is not working. </p>
  
  <pre><code>ssh remote_server "if [ '$(grep -oP \"^[0-9]+\" /proc/uptime)' -le 600 ];then echo  remote_server Failed ;exit 1;else echo remote_server passed ;fi"
  </code></pre>
  
  <p>I also tried following approach to convert if condition to multi line in ansible. but it is also not working. </p>
  
  <pre><code>  - name: get the uptime of all nodes
      shell:  |
      ssh {{ item }} " bash &lt;&lt;'EOF'
      if [ '$(grep -oP \"^[0-9]+\" /proc/uptime)' -le 600 ];then
          echo  {{ item }} Failed ;
          exit 1;
       else
          echo {{item }} passed ;
       fi
       "
       EOF
      with_items:
        - "{{ node_list.stdout_lines }}"
      become: true
  </code></pre>
  
  <p>The offending line appears to be:</p>
  
  <pre><code>       ssh {{ item }} " bash &lt;&lt;'EOF'
          if [ '$(grep -oP \"^[0-9]+\" /proc/uptime)' -le 600 ];then
          ^ here
  
  exception type: &lt;class 'yaml.scanner.ScannerError'&gt;
  exception: while scanning a simple key
    in "&lt;unicode string&gt;", line 51, column 9
  could not find expected ':'
    in "&lt;unicode string&gt;", line 52, column 9
  </code></pre>
  
  <p>Update:</p>
  
  <pre><code> shell:  ssh {{ item }} 'if [ "$(grep -oP '^[0-9]+' /proc/uptime) -le 600 ]; then echo failed; exit 1; else echo passed; fi'
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>"start": "2019-02-07 15:05:36.740756",
  "stderr": "bash: -c: line 0: unexpected EOF while looking for matching `\"'\nbash: -c: line 1: syntax error: unexpected end of file",
  "stderr_lines": [
      "bash: -c: line 0: unexpected EOF while looking for matching `\"'",
      "bash: -c: line 1: syntax error: unexpected end of file"
  ],
  "stdout": "",
  "stdout_lines": []
  </code></pre>