title: Getting Unexpected templating type error occurred while assigning value to set_fact with Ansible
body: <p>Getting Unexpected templating type error occurred while assigning value to set_fact with Ansible</p>
  
  <p>Below is my playbook:</p>
  
  <pre><code>   - name: Load entire repository inventory
       include_vars:
         file="{{ playbook_dir }}/repository/inform/gac.yaml"
         name=user1
  
     - debug:
         msg: "ALERT !! File {{ user1[inventory_hostname][item.stat.path] }} has changed {{ inventory_hostname }}"
       when: item.stat.checksum != user1[inventory_hostname][item.stat.path].hash
       with_items: "{{ files_det.results }}"
  
  
     - name: Gather all files
       tags: always
       set_fact:
         msg_body: "{{ msg_body | default('') + user1[inventory_hostname][item.stat.path] + 'has changed' + inventory_hostname +'. Rollback' + '\n' }}"
       when: item.stat.checksum != user1[inventory_hostname][item.stat.path].hash
       with_items: "{{ files_det.results }}"
  </code></pre>
  
  <p>I recieve error with set_fact as below:</p>
  
  <pre><code>"msg": "ALERT !! File {u'hash': u'1746f03d5741b27158b0d3a48fca8b5fa85c0c2'} has changed 10.9.9.66"
  
  
  TASK [Gather all files] ***************************************************************************************************************
  task path: /app/fg_test.yml:2
  META: noop
  fatal: [10.9.9.66]: FAILED! =&gt; {
      "msg": "Unexpected templating type error occurred on ({{ msg_body | default('') + user1[inventory_hostname][item.stat.path] + 'has changed' + [inventory_hostname] +'. Rollback' + '\n' }}): cannot concatenate 'str' and 'dict' objects"
  }
  META: noop
  </code></pre>
  
  <p>I even tried </p>
  
  <pre><code>   msg_body: "{{ msg_body | default('') + user1[inventory_hostname][item.stat.path] + 'has changed' + [inventory_hostname] +'. Rollback' + '\n' }}"
  </code></pre>
  
  <p>but that too did not help. </p>
  
  <p>Can you please suggest what is the issue with my code ?</p>