Merging dicts in Ansible

Posted on Wed 27 April 2022 in Sysadmin • Tagged with ansible

I spent way to much time figuring out this simple problem. In Ansible I wanted to have a top-level dict variable in the inventory that could be overridden by a host-level dict.

Example inventory file:

all:
  vars:
    dict1:
      thing1: stuff
      thing2: more stuff
  children:
    some_machines:
      hosts:
        server-a:
        server-b:
          dict1:
            thing1 …

Continue reading