Delete a nested dictionary in host config which is given by host template?

Hi all,
I have a bunch of server with the same checks, which are all configured with a host template and dictionaries, e.g.

apply Service "by_ssh: " for ( by_ssh => config in host.vars.by_ssh) {
  import "by_ssh"
  vars += config
  assign where host.vars.by_ssh
}

template Host "bla" {
....
  vars.by_ssh["Service a"] = {
    by_ssh_command = "a"
  }
  vars.by_ssh["Service b"] = {
    by_ssh_command = "b"
  }
  vars.by_ssh["Service c"] = {
    by_ssh_command = "c"
  }
  vars.by_ssh["Service d"] = {
    by_ssh_command = "d"
  }
  and so on.... 
}

On 99.9% of the server, which have this template imported, it fits. But on one or two server, I have to delete specific dictionaries, e.g. “Service d”.
So I would like to delete it in the host configuration instead of not importing the template and add the whole config to the host.
I know, there is a vars.remove("x") function. But I could not find a way to delete the specific Service dictionary.
With vars.remove("by_ssh") I just delete all “by_ssh” Services, but things like vars.remove("by_ssh["Service d"]") díd not work.
How do I have to remove it (there is a space in the Service name) ?

Cheers and thanks,
Marcus

Not sure about, but I would simply try to override the value to null.

Does not work, dictionary stays but without any keys/values:
Output from icinga2 object list

  * vars
    * by_ssh
	..............
      * service_b = null
        % = modified in '...', lines 57:3-59:3 <- template config
        % = modified in '...', lines 4:3-4:33 <- vars.by_ssh.service_b = null (in host config)

I got it!
vars.by_ssh.remove("service_b")

1 Like