# Template to include contents of another file

**URL:** <https://forum.ansible.com/t/template-to-include-contents-of-another-file/14861>\
**Category:** Ansible Project\
**Created:** [March 26, 2014, 10:21am UTC](https://forum.ansible.com/t/template-to-include-contents-of-another-file/14861 "2014-03-26T10:21:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [March 26, 2014, 10:21am UTC](https://forum.ansible.com/t/template-to-include-contents-of-another-file/14861/1 "2014-03-26T10:21:35Z")

</div>

Dear List,

I’m trying to have a template placed on some servers and while the file is beeing placed to contain the contents of another file (Public key) like so:  
[http://jinja.pocoo.org/docs/templates/#include](http://jinja.pocoo.org/docs/templates/#include)

**encapmodule-properties.j2:**

> encap-public-key={% include ‘/opt/encapserver.crt’ %}
> 
> assertion-time-skew=5
> 
> registrationIdLdapAttrName=binckMobileDeviceID
> 
> includeSignatureValidation=true
> 
> includeBeforeAndAfterValidation=true
> 
> includeIssuerValidation=false
> 
> includeStatusCodeValidation=false
> 
> expectedIssuer=encap

As you can see, I tried to include the “/opt/encapserver.crt” file on the machine beeing managed at that moment.

> mmaas@xmgtansible:~/playbooks$ ansible-playbook forge\_rock.yml -l t1atham\* -vvvv --tags=test  
> But i’m running into this error:  
> TASK: [openam | Plaats binck\_encapmodule.properties] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ESTABLISH CONNECTION FOR USER: mmaas  
> EXEC [‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/mmaas/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, ‘t1athamyar’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1395828889.82-55430178152696 && chmod a+rx $HOME/.ansible/tmp/ansible-1395828889.82-55430178152696 && echo $HOME/.ansible/tmp/ansible-1395828889.82-55430178152696’”]  
> fatal: [t1athamyar] =\> {‘msg’: ‘/opt/encapserver.crt’, ‘failed’: True}  
> fatal: [t1athamyar] =\> {‘msg’: ‘/opt/encapserver.crt’, ‘failed’: True}

Any idea’s?

I could ofcourse simply “cat” the contents of that file and register the output as a variable. And then use that variabel. But that would not be as clean as when using jinja2 stuff directly 😉

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [March 26, 2014, 12:58pm UTC](https://forum.ansible.com/t/template-to-include-contents-of-another-file/14861/2 "2014-03-26T12:58:02Z")

</div>

templates get composed locally and then copied to the target. You might want to use fetch/slurp on the file to have it available locally to include.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [March 26, 2014, 1:08pm UTC](https://forum.ansible.com/t/template-to-include-contents-of-another-file/14861/3 "2014-03-26T13:08:50Z")

</div>

I tried that, sorta, by copying it to that location (/opt) on the “local” machine. Same error though…
