Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variables for different models within groups #2482

Merged
4 commits merged into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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)
- Extended `remote_repo` configuration to allow repo specific ssh keys (@mjbnz)
- sonicos: added scrubbing for hashed values (@televat0rs)
- nxos: Additional scrubbing for nxos device passwords (@derekivey)
Expand Down
22 changes: 22 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,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"
```

For mapping multiple group values to a common name

```yaml
Expand Down
7 changes: 5 additions & 2 deletions lib/oxidized/config/vars.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down