-
-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem: If one has to set a lot of variables in many files (for example, using each()), you have to repeat yourself a lot.
For example, this is the cleanest I've been able to write for setting many variables.
Shellvar {
ensure => present,
target => $ifile,
}
shellvar { "${name} DEVICE": variable => 'DEVICE', value => $name}
shellvar { "${name} NAME": variable => 'NAME', value => $name}
shellvar { "${name} HWADDR": variable => 'HWADDR', value => $hwaddress}
shellvar { "${name} TEAM_MASTER": variable => 'TEAM_MASTER', value => $team_master}
shellvar { "${name} DEVICETYPE": variable => 'DEVICETYPE', value => 'TeamPort'}
shellvar { "${name} ONBOOT": variable => "TYPE", value => 'yes'}
shellvar { "${name} TYPE": variable => 'TYPE', value => 'Ethernet'}
shellvar { "${name} NM_CONTROLLED": value => 'NM_CONTROLLED', variable => 'no'}There are a few problems with this:
- The namevar repeats the variable name, which is error prone. They may get out of sync.
- Specifying
variable =>andvalue =>again and again is very verbose. It hides meaning. - It is slow. Each one of these will require starting up augeas, parsing the file, etc.
- You didn't notice that "ONBOOT" sets the wrong variable, or that NM_CONTROLLED reversed the value and the variable.
Proposed Solution: For mass updates, it would be more natural to have a function that takes a filename and a list of settings:
shellvar_bulk( $ifile, [
"DEVICE=$name",
"NAME=$name",
"HWADDR=$hwaddress",
"TEAM_MASTER=$TEAM_MASTER",
'DEVICETYPE=TeamPort',
'ONBOOT=yes',
'TYPE=Ethernet',
'NM_CONTROLLED=no',
])Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request