Hi Marc,

On 25.05.19 20:42, Marc Haber wrote:
> this is what I have in a YAML formatted inventory
> 
> ---
> all:
>   vars:
>     city:
>       - Berlin
>   children:
>     g_empty:
>       hosts:
>         emptybuster:
>         emptysid:
>         emptystretch:
>           city:
>             - Steglitz
> 
> Is there a more elegant way to do this, or have I reached ansible's
> limits? If so, is there a bug report against ansible where I could read
> up on the situation?

Well, Ansibles variable system isn't as featureful as e.g. hiera and
works mostly with overwrites.

I see two possibilities here:

1. Using the a lookup plugin, not inventory variables, e.g. hiera since
it supports all kinds of merging

https://docs.ansible.com/ansible/latest/plugins/lookup/hiera.html

2. Use a different name for the variables and use set_fact in your
playbook/a role to merge them.

---
all:
  vars:
    _city_all:
      - Berlin
  children:
    g_empty:
      hosts:
        emptystretch:
          city:
            - Steglitz


---
- hosts: all
  pre_tasks:
    - set_fact:
        city: "{{ _city_all + city | default([]) }}"
  tasks:
    - debug:
        var: city


HTH,
Sebastian

-- 
Sebastian Meyer
Linux Consultant & Trainer
Mail: [email protected]

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

-- 
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/bbaa6af3-5406-a10d-0ed4-f1fa9ddd8644%40b1-systems.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to