Merging two dictionaries from different files.

I’m have two files one which represents the default case, and another for a specific environment.

variables/all.yml:
all:
vars:
myapp:
COMPONENT_NAME: “app”
(and another hundred or so default settings for myapp)

variables/devenv.yml:
all:
vars:
myapp:
PORT_NUMBER: 5678

I want Ansible to merge these inside a role :-

roles/tasks/main.yml:

  • name: Create working Directory
    file:
    path: “{{ WORKING_DIR }}/{{ Values.COMPONENT_NAME }}”
    state: directory
    recurse: yes

Sorry, my Ansible is a little rusty. I guess I need to use a combine to merge the two yaml dictionaries, but not sure where to put it?

Have been looking at this solution, but it’s not quite what I need.

Also, the way I’ve inherited it the variables folder is shared across a bunch of roles.

Hope this is clear!? I’m just trying to figure out where I should utilise “combine”

Thanks!

When I said “This solution” I meant to post the link…

https://groups.google.com/g/ansible-project/c/pGbRYZyqxZ4