title: 'cat' command in ansible playbook wont append file
body: <p>I am new to ansible and am currently trying to create a simple playbook that installs ssmtp, sends a message (with the body being the contents of a given file) then erases ssmtp again. I have /tmp/message.txt where the 'from', 'to' and other details are stored and the /tmp/file.txt which just has two rows of 12345678.</p>
  <p>The goal is to have an email sent out that has the subject 'test' and the body just being the two rows of the numbers. What I can't understand though is why the &quot;cat /tmp/file.txt &gt;&gt; /tmp/message.txt&quot; does not append the contents of file.txt to message.txt This works fine when just run as a command in the terminal or when the same commands are used in a bash script. I get that this is probably an easy oversight, but after trying several other commands I can't seem to reach a solution. Playbook text is below:</p>
  <pre><code>---
   - name: install ssmtp and send email
     hosts: the_server_itself
     become: true
     become_user: root
     tasks:
       - name: &quot;install ssmtp&quot;
         yum: 
           name: ssmtp 
           state: latest
           
       - name: &quot;add mail provider&quot;
         shell:
           cmd: echo -e &quot;mailhub=smtp.gmail.com:587\n&quot; &gt;&gt; /etc/ssmtp/ssmtp.conf
       - name: &quot;add auth settings&quot;
         shell:
           cmd: echo -e &quot;UseSTARTTLS=Yes \nAuthUser=&lt;username&gt; \nAuthPass=&lt;password&gt; \nAuthMethod=LOGIN \n&quot; &gt;&gt; /etc/ssmtp/ssmtp.conf
           
       - name: &quot;send out email&quot;
         shell:
          cmd: chfn -f &quot;&lt;sender name&gt;&quot; root
       - name: &quot;create message file&quot;
         file:
          path: /tmp/message.txt
          state: touch
       - name: &quot;append message file&quot; 
         shell: 
           cmd: 'echo -e &quot;From: &lt;sender@mail.provider&gt;\nSubject: Test\n\n&quot; &gt; /tmp/message.txt'
       - name: &quot;add file to  message&quot;
         shell: 
           cmd: 'cat /tmp/file.txt &gt;&gt; /tmp/message.txt'
         shell: 
           cmd: ssmtp  &lt;recipient@mail.provider&gt; &lt; /tmp/message.txt
           
       - name: &quot;erase ssmtp&quot;
         yum:
           name: ssmtp
           state: removed
       - name: &quot;erase message.txt&quot;
         file:
           path: /tmp/message.txt
           state: absent
  ...
  
  </code></pre>
  <p>And thanks in advance to anyone who replies!</p>