title: How to write a variable value in a file using ansible.builtin.template module?
body: <p>I wanted to log content of a variable in a file. I did it like this,</p>
  <pre><code> - name: write infraID to somefile.log
      copy:
        content: &quot;{{ infraID.stdout }}&quot;
        dest: somefile.log
  </code></pre>
  <p>And it worked. But in the documentation for <code>copy</code> <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#parameter-content" rel="nofollow noreferrer">here</a>, I found that they have recommended to use <code>template</code> instead of <code>copy</code> in such cases.</p>
  <blockquote>
  <p>For advanced formatting or if <code>content</code> contains a variable, use the
  ansible.builtin.template module.</p>
  </blockquote>
  <p>I went through the examples given at the documentation for template module <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html#examples" rel="nofollow noreferrer">here</a>. But I was unable to figure out something that works in my scenario. Could you please show me how to do this properly in recommended way ?
  Thanks in advance !! Cheers!</p>