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.

On Friday, 5 December 2014 17:07:53 UTC+1, David Stark wrote:
>
> 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 
> <Virtualhost>:
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7bc87829-4085-4a50-9b42-6356be208172%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to