title: Retrieving contents of j2 template file on stdout
body: <p>I'm attempting to use Ansible to better manage my Kubernetes configmaps in a multienvironment project (dev, stage, and prod). I've generalized each of the config maps as j2 templates, and I'll override the variables depending on how they might change in different environments (so that they aren't duplicated three times for basically the same file).</p>
  
  <p>My playbook currently looks something like this:</p>
  
  <pre><code>---
  - hosts: localhost
    vars_files:
      - "vars/{{ env }}.yml"
    tasks:
      - name: Generate YAML from j2 template
        template:
          src: templates/foo.j2
          dest: output/foo.yml
  </code></pre>
  
  <p>And this has been working great for testing so far. However, I'm at the point where I want to incorporate this into my already existing Jenkins CI/CD, but I'm having trouble understanding how it might work with what I am doing currently.</p>
  
  <p>After generating what is basically a Kuberenets ConfigMap from the j2, I'll somehow do this within Jenkins:</p>
  
  <pre><code>kubectl apply -f &lt;yaml&gt;
  </code></pre>
  
  <p>However, the playbook is creating a YAML file every time I run it, and I am wondering if there is an alternative that would allow me to pipe the contents of the YAML file or somehow retrieve it from stdout.</p>
  
  <p>Basically, I want to evaluate the template and retrieve it without necessarily creating a file.</p>
  
  <p>If I do this, I could do something like the following:</p>
  
  <pre><code>echo result | kubectl apply -f -
  </code></pre>
  
  <p>where result of course is the contents of the YAML file that results after the templating, and the short dash after the f flag specifies Kubernetes to use the process' stdout.</p>
  
  <p>Sorry for so much explaining, I can clarify anything if needed.</p>