Skip to content

Instantly share code, notes, and snippets.

@berlic
Created July 25, 2017 08:01
Show Gist options
  • Save berlic/bedf6024ca9aa327ae15f65412c37668 to your computer and use it in GitHub Desktop.
Save berlic/bedf6024ca9aa327ae15f65412c37668 to your computer and use it in GitHub Desktop.
yaml combine
---
- hosts: localhost
gather_facts: no
vars:
config_files:
- test1
- test2
tasks:
- name: Load config defaults
include_vars:
file: "{{ item }}.yml"
name: "default_config"
with_items: "{{ config_files }}"
register: default_configs
tags:
- configuration
- name: Combine configs into one dict
# Здесь мы делаем словарь вида
# default_configs:
# config_name_1: { default_config_object }
# config_name_2: { default_config_object }
# config_name_3: { default_config_object }
# ...
set_fact:
default_configs: "{{ dict(default_configs.results | json_query('[].[item, ansible_facts.default_config]')) }}"
tags:
- configuration
- debug:
var: default_configs
hello: world
@berlic
Copy link
Author

berlic commented Jul 25, 2017

$ ansible --version
ansible 2.2.1.0
$ pip list | grep -iP 'jinja|jmes'
Jinja2 (2.8)
jmespath (0.9.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment