Template to include contents of another file

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

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 :wink:

Thanks,
Mark

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.

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