I have the following code:
if (!EAP-Message) {
# Now check against the authorized_macs file
<%- @filename.each do |key,value| -%>
<%= key %>
if (!ok) {
<%- end -%>
eap
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
eap
}
I would like to indent the file properly by adding indentation or spaces or tabs after each loop, so that it looks like this:
if (!EAP-Message) {
# Now check against the authorized_macs file
authorized_macs_10
if (!ok) {
authorized_macs_11
if (!ok) {
authorized_macs_12
if (!ok) {
authorized_macs_13
if (!ok) {
authorized_macs_14
if (!ok) {
eap
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
# accept
update control {
Auth-Type := Accept
}
}
}
else {
eap
}
This is a part of the /etc/freeradius/sites-available/default of my freeradius puppet module, which is finally done. The @filename
variable is a hiera_hash, which I get from a yaml file. Here is the relevant part:
test_freeradius::files:
'authorized_macs_10':
macs:
- 'aaaaa'
- 'bbbbb'
vlan: '10'
'authorized_macs_11':
macs:
- 'ccccc'
- 'ddddd'
vlan: '11'
'authorized_macs_12':
macs:
- 'eeeee'
- 'fffff'
vlan: '12'
'authorized_macs_13':
macs:
- 'ggggg'
- 'hhhhh'
vlan: '13'
'authorized_macs_14':
macs:
- 'iiiii'
- 'jjjjj'
vlan: '14'
And below is the define I use to create among other things the content of the default
file:
define test_freeradius::files (
$macs,
$vlan,
$macfile = $title,
) {
include test_freeradius::service
ensure_resource('file', '/etc/freeradius/modules/files', {
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/files.erb"),
require => Class['test_freeradius::install'],
notify => Service['freeradius'],
}
)
file { "/etc/freeradius/${macfile}" :
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/macfiles.erb"),
require => Class['test_freeradius::install'],
notify => Service['freeradius'],
}
ensure_resource('file', '/etc/freeradius/sites-available/default', {
ensure => 'file',
owner => 'root',
group => 'freerad',
mode => '0644',
content => template("${module_name}/default.erb"),
require => Class['test_freeradius::install'],
notify => Service['freeradius'],
}
)
ensure_resource('file', '/etc/freeradius/sites-enabled/default', {
ensure => 'link',
target => '/etc/freeradius/sites-available/default',
}
)
}
The loop does what it should, but without indentation, I tried different things like adding <%= " "%>
at several positions and creating a variable for the if (!ok) {
part, unfortunately without success, maybe I should restructure the code? any ideas?