title: splitting string by whitespace and then joining it again in ansible/jinja2
body: <p>I'm trying to "cleanup" whitespaces in a variable in Ansible (ansible-2.1.1.0-1.fc24.noarch) playbook and I though I'll first <strong>split()</strong> it and then <strong>join(' ')</strong> again. For some reason that approach is giving me error below :-/</p>
  
  <pre><code>---
  - hosts: all
    remote_user: root
    vars:
      mytext: |
        hello
        there how   are
        you?
    tasks:
      - debug:
          msg: "{{ mytext }}"
      - debug:
          msg: "{{ mytext.split() }}"
      - debug:
          msg: "{{ mytext.split().join(' ') }}"
  ...
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre><code>TASK [debug] *******************************************************************
  ok: [192.168.122.193] =&gt; {
      "msg": "hello\nthere how   are\nyou?\n"
  }
  
  TASK [debug] *******************************************************************
  ok: [192.168.122.193] =&gt; {
      "msg": [
          "hello", 
          "there", 
          "how", 
          "are", 
          "you?"
      ]
  }
  
  TASK [debug] *******************************************************************
  fatal: [192.168.122.193]: FAILED! =&gt; {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'join'\n\nThe error appears to have been in '.../tests.yaml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        msg: \"{{ mytext.split() }}\"\n    - debug:\n      ^ here\n"}
  </code></pre>
  
  <p>Any idea on what I'm doing wrong? It says <em>the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'join'</em>, but according to <a href="http://docs.ansible.com/ansible/playbooks_filters.html#other-useful-filters" rel="noreferrer">useful filters</a> docs, it should work.</p>