title: Ansible: Set variable to file content
body: <p>I'm using the ec2 module with <code>ansible-playbook</code> I want to set a variable to the contents of a file. Here's how I'm currently doing it. </p>
  
  <ol>
  <li>Var with the filename</li>
  <li>shell task to <code>cat</code> the file</li>
  <li>use the result of the <code>cat</code> to pass to the ec2 module.</li>
  </ol>
  
  <p>Example contents of my playbook.</p>
  
  <pre><code>vars:
    amazon_linux_ami: "ami-fb8e9292"
    user_data_file: "base-ami-userdata.sh"
  tasks:
  - name: user_data_contents
    shell: cat {{ user_data_file }}
    register: user_data_action
  - name: launch ec2-instance
    local_action:
  ...
    user_data: "{{ user_data_action.stdout }}"
  </code></pre>
  
  <p>I assume there's a much easier way to do this, but I couldn't find it while searching Ansible docs.</p>