Thanks James and everyone, the other night I ended up doing almost exactly 
like what you suggested and it works great!

Cheers,
Mark

On Wednesday, October 8, 2014 2:41:17 AM UTC+2, James Martin wrote:
>
> Mark G.,
>
> The to_json (or to_nice_json) filter and a template will do the magic you 
> want.  Given this playbook:
>
> - hosts: localhost
>   connection: local
>   vars:
>     log_paths:
>     - "/logs/access.log"
>     - "/logs/error.log"
>   tasks:
>   - name: create config file
>     template: src=logstash.json.j2 dest=/tmp/logstash.json
>
>
> and this template:
>
>
> {
>   "network": {
>     "servers": [ "1.2.3.4:5000" ],
>     "timeout": 15,
>     "ssl ca": "/etc/pki/tls/certs/logstash-forwarder.crt"
>   },
>   "files": [
>     {
>       "paths": {{ log_paths | to_json }},
>       "fields": { "type": "web_nginx_access" }
>     }
>    ]
> }
>
>
>
> Will render:
>
> {
>   "network": {
>     "servers": [ "1.2.3.4:5000" ],
>     "timeout": 15,
>     "ssl ca": "/etc/pki/tls/certs/logstash-forwarder.crt"
>   },
>   "files": [
>     {
>       "paths": ["/logs/access.log", "/logs/error.log"],
>       "fields": { "type": "web_nginx_access" }
>     }
>    ]
> }
>
>
> - James
>
> On Sunday, October 5, 2014 5:17:56 PM UTC-4, Mark Gavalda wrote:
>>
>> Hi,
>>
>> I'm trying to add lines to the Logstash Forwarder config file, which 
>> looks like this right now:
>>
>> {
>>   "network": {
>>     "servers": [ "1.2.3.4:5000" ],
>>     "timeout": 15,
>>     "ssl ca": "/etc/pki/tls/certs/logstash-forwarder.crt"
>>   },
>>   "files": [
>>     {
>>       "paths": [
>>         "/logs/access.log"
>>        ],
>>       "fields": { "type": "web_nginx_access" }
>>     }
>>    ]
>> }
>>
>> And I'd like to add other logs in that files.paths array, then save it. 
>> The problem is that starting from the second line I will have to add the 
>> commas to not screw up the JSON syntax... how can I do that with Ansible.
>> I've tried so many solutions, just can't figure this one out.
>>
>> I was thinking about using a "command cat logstash-forwarder.conf" plus 
>> "register: result" then somehow manipulating the object with {{ 
>> result.stdout|from_json }} but that's as far as I got. I'd really 
>> appreciate any comments.
>>
>> Thanks,
>> Mark
>>
>

-- 
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/f8782ac4-2618-496a-97d1-29e626796235%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to