freifunkh / ansible-configs

Here we store all of our actual ansible hosts in freifunk hanover
2 stars 1 forks source link

Create vars/all_sn.yml to reduce redundancy #14

Closed lemoer closed 4 years ago

lemoer commented 7 years ago

There are a lot of variables, that are shared between all supernodes. We should outsource them into an own file vars/all_sn.yml

lemoer commented 7 years ago
- dns_recursive_allowed_private_rdns_zones:
  - "8.0.0.0.e.e.f.f.a.c.d.f.ip6.arpa."

from vars/all_hosts.yml should be migrated to there as well.

lemoer commented 6 years ago

Maybe we could use another level of abstaction with include:

supernode.yml:

---

- hosts: sn01
  tasks:
  - name: foo und bar
    set_fact:
      a:
        c: ['foo', 'bar']

  - name: print
    debug: var=a

  - include: add_it.yml b="hey"

  - include: add_it.yml b="hey"

  - name: print
    debug: var=a

add_it.yml:

--- 
- name: add it
  set_fact:
    a: "{{ a|combine({ \"c\": a[\"c\"] + [b] }) }}"

This include snippet adds variable b into array in a["c"].

output:

PLAY [sn01] ***********************************************************************************

TASK [Gathering Facts] ************************************************************************
ok: [sn01]

TASK [foo und bar] ****************************************************************************
ok: [sn01]

TASK [print] **********************************************************************************
ok: [sn01] => {
    "a": {
        "c": [
            "foo", 
            "bar"
        ]
    }, 
    "changed": false
}

TASK [add it] *********************************************************************************
ok: [sn01]

TASK [add it] *********************************************************************************
ok: [sn01]

TASK [print] **********************************************************************************
ok: [sn01] => {
    "a": {
        "c": [
            "foo", 
            "bar", 
            "hey", 
            "hey"
        ]
    }, 
    "changed": false
}

PLAY RECAP ************************************************************************************
sn01                       : ok=6    changed=0    unreachable=0    failed=0   
1977er commented 6 years ago

Can you add a tangible example please? ;-)

1977er commented 6 years ago

And everybody is complaining about Perl regexes.