From 4405833c531520dc3ab7ed5178efc78ae5185fc9 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Thu, 17 Feb 2022 23:38:05 +0000 Subject: [PATCH 1/2] Support vars for models within groups. Signed-off-by: Mike Beattie --- lib/oxidized/config/vars.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/oxidized/config/vars.rb b/lib/oxidized/config/vars.rb index 79ca42f62..e184629ef 100644 --- a/lib/oxidized/config/vars.rb +++ b/lib/oxidized/config/vars.rb @@ -1,12 +1,15 @@ module Oxidized::Config::Vars # convenience method for accessing node, group or global level user variables def vars(name) + model_name = @node.model.class.name.to_s.downcase if @node.vars&.has_key?(name) @node.vars[name] + elsif Oxidized.config.groups.has_key?(@node.group) && Oxidized.config.groups[@node.group].models.has_key(model_name) && Oxidized.config.groups[@node.group].models[model_name].vars.has_key?(name.to_s) + Oxidized.config.groups[@node.group].models[model_name].vars[name.to_s] elsif Oxidized.config.groups.has_key?(@node.group) && Oxidized.config.groups[@node.group].vars.has_key?(name.to_s) Oxidized.config.groups[@node.group].vars[name.to_s] - elsif Oxidized.config.models.has_key(@node.model.class.name.to_s.downcase) && Oxidized.config.models[@node.model.class.name.to_s.downcase].vars.has_key?(name.to_s) - Oxidized.config.models[@node.model.class.name.to_s.downcase].vars[name.to_s] + elsif Oxidized.config.models.has_key(model_name) && Oxidized.config.models[model_name].vars.has_key?(name.to_s) + Oxidized.config.models[model_name].vars[name.to_s] elsif Oxidized.config.vars.has_key?(name.to_s) Oxidized.config.vars[name.to_s] end From 19de4272eb90af5617507d7cca4be7699207fd3d Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Wed, 9 Mar 2022 00:54:34 +0000 Subject: [PATCH 2/2] Update Documentation Signed-off-by: Mike Beattie --- CHANGELOG.md | 1 + docs/Configuration.md | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83cc1686c..c89c8510b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - only runs SSH proxy commands if the ssh_proxy configuration item has been defined (@jameskirsop) - updated vrp.rb to correctly parse huawei devices - asa: information about the configuration change time is deleted +- Extended groups configuration to support models vars within a group (@mjbnz) ### Fixed diff --git a/docs/Configuration.md b/docs/Configuration.md index 8b44e9330..20329a111 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -238,6 +238,28 @@ groups: password: ubnt ``` +Model specific variables within groups + +```yaml +groups: + foo: + models: + arista: + vars: + ssh_keys: "~/.ssh/id_rsa_foo_arista" + vyatta: + vars: + ssh_keys: "~/.ssh/id_rsa_foo_vyatta" + bar: + models: + routeros: + vars: + ssh_keys: "~/.ssh/id_rsa_bar_routeros" + vyatta: + vars: + ssh_keys: "~/.ssh/id_rsa_bar_vyatta" +``` + and add group mapping ```yaml