# template failure on a rather odd looking file (for apache+logstash)

**URL:** <https://forum.ansible.com/t/template-failure-on-a-rather-odd-looking-file-for-apache-logstash/16972>\
**Category:** Ansible Project\
**Created:** [December 5, 2014, 4:07pm UTC](https://forum.ansible.com/t/template-failure-on-a-rather-odd-looking-file-for-apache-logstash/16972 "2014-12-05T16:07:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Stark](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@David\_Stark](https://forum.ansible.com/u/David_Stark)\
**Post date:** [December 5, 2014, 4:07pm UTC](https://forum.ansible.com/t/template-failure-on-a-rather-odd-looking-file-for-apache-logstash/16972/1 "2014-12-05T16:07:53Z")

</div>

Hi everyone

Sorry if this comes across as a bit of a silly questions but this has been my first real ansible issue that I couldn’t resolve.

What I currently do is to declare a special **LogFormat** for apache. This spits out nice friendly json formatting for my vhosts and logstash to slurp.

The file I want to template looks a little like this (end result)  
(variables in bold)

[root@webserver1 httpd]# cat /etc/httpd/conf.d/10-logstash.conf  
LogFormat “{   
"host":" **webserver1**",   
"path":"/var/log/httpd/logstash\_access\_log",   
"tags":[" **cluster2**"],   
"message": "%h %l %u %t \"%r\" %\>s %b",   
"timestamp": "%{%Y-%m-%dT%H:%M:%S%z}t",   
"useragent": "%{User-agent}i",   
"clientip": "%a",   
"duration": %D,   
"status": %\>s,   
"request": "%U%q",   
"urlpath": "%U",   
"urlquery": "%q",   
"method": "%m",   
"bytes": %B,   
"vhost": "%v"   
}” logstash\_apache\_json

If you’re interested in ELK I then just have this declared withing a :  
CustomLog “/var/log/httpd/logstash\_access.log” logstash\_apache\_json

So I’ve changed the above to {{ ansible\_hostname }} and a var I declare as normal but I can’t seem to write the file with the template module:

TASK: [template /etc/httpd/conf.d/10-logstash.conf] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [10.1.2.75] =\> {‘msg’: “AnsibleError: file: /home/starkd/uk-cluster2-httpdconfigs/templates/etc/httpd/conf.d/10-logstash.conf.j2, line number: 6, error: Encountered unknown tag ‘Y’.”, ‘failed’: True}  
fatal: [10.1.2.75] =\> {‘msg’: “AnsibleError: file: /home/starkd/uk-cluster2-httpdconfigs/templates/etc/httpd/conf.d/10-logstash.conf.j2, line number: 6, error: Encountered unknown tag ‘Y’.”, ‘failed’: True}

FATAL: all hosts have already failed – aborting

(the task is very simple:)

- name: template /etc/httpd/conf/httpd.conf  
template: \>  
src=templates/etc/httpd/conf/httpd.conf.j2  
dest=/etc/httpd/conf/httpd.conf  
owner=root  
group=root  
mode=0644  
notify: restart httpd

So I know I can copy the file and maybe use lineinfile to update these (or maybe a script)

I just can’t figure out a way of doing this “properly”

Any advice welcome!  
Many thanks

-David

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [January 3, 2015, 8:02pm UTC](https://forum.ansible.com/t/template-failure-on-a-rather-odd-looking-file-for-apache-logstash/16972/2 "2015-01-03T20:02:47Z")

</div>

Can you show the contents of templates/etc/httpd/conf/httpd.conf.j2? Seems you’re cat’ing the file directly on the target host.

BTW, when using the template module you don’t need to specify ‘templates/’ in the src. Same for the copy module with the ‘files/’), etc.
