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

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

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.