Impossible, how to combine several arrays into one file?

Using this as my template: https://github.com/modcloth/ansible-role-modcloth-sumologic-collector - It works great, but I'm looking for some suggestions on how to expand it for my intended needs. I need to create a JSON file based on multiple arrays.

Below is the default array that I need in the SumoLogic JSON source.

role / sumologic / defaults / main.yml:

sumologic_collector_default_log_path:

- { name: "Auth Log", path: "/var/log/auth.log", use_multiline: false, category: "OS/Linux/Auth" } 

Let's say I want to add an additional file to the SumoLogic JSON file from group_vars / app_server.yml:

 - { name: "Package Log", path: "/var/log/nginx/access.log", use_multiline: fasle, category: "OS/Linux/Nginx" } 

How to combine the above examples using a template into the same destination file?

We are pleased to provide more detailed information. I'm not quite sure that my thought approach makes sense, although I think set_fact is one way to do this, and I could not figure it out enough to understand the way.

+6
source share
1 answer

Jinja2, Ansible's template engine gives you the ability to easily merge lists:

 array1 + array2 

Here is a complete playbook example:

 --- - name: Testing hosts: localhost gather_facts: no vars: array1: - a - b - c array2: - x - y - z tasks: - debug: msg="{{ array1 + array2 }}" ... 

Output:

 PLAY [Testing] **************************************************************** TASK: [debug msg="{{ array1 + array2 }}"] ************************************* ok: [localhost] => { "msg": "['a', 'b', 'c', 'x', 'y', 'z']" } PLAY RECAP ******************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=0 
+18
source

Source: https://habr.com/ru/post/981795/


All Articles