Skip to content

Commit

Permalink
Merge pull request #89 from jhoblitt/bugfix/ipmi.default.channel
Browse files Browse the repository at this point in the history
add ipmi::default_channel param to fix chicken and egg failure
  • Loading branch information
jhoblitt authored Sep 24, 2024
2 parents a77598b + 3c8f98a commit 5b681e6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 48 deletions.
4 changes: 1 addition & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
fixtures:
forge_modules:
stdlib:
repo: "puppetlabs/stdlib"
ref: "8.6.0"
stdlib: "puppetlabs/stdlib"
augeas_core: "puppetlabs/augeas_core"
21 changes: 15 additions & 6 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The following parameters are available in the `ipmi` class:
* [`snmps`](#-ipmi--snmps)
* [`users`](#-ipmi--users)
* [`networks`](#-ipmi--networks)
* [`default_channel`](#-ipmi--default_channel)

##### <a name="-ipmi--packages"></a>`packages`

Expand Down Expand Up @@ -104,6 +105,14 @@ Data type: `Optional[Hash]`

`ipmi::network` resources to create.

##### <a name="-ipmi--default_channel"></a>`default_channel`

Data type: `Integer[0]`

Default channel to use for IPMI commands.

Default value: `Integer(fact('ipmi.default.channel') or 1)`

## Defined types

### <a name="ipmi--network"></a>`ipmi::network`
Expand Down Expand Up @@ -154,12 +163,12 @@ Default value: `'dhcp'`

##### <a name="-ipmi--network--lan_channel"></a>`lan_channel`

Data type: `Integer`
Data type: `Optional[Integer]`

Controls the lan channel of the IPMI network to be configured.
Defaults to the first detected lan channel, starting at 1 ending at 11

Default value: `$facts['ipmi']['default']['channel']`
Default value: `undef`

### <a name="ipmi--snmp"></a>`ipmi::snmp`

Expand All @@ -182,12 +191,12 @@ Default value: `'public'`

##### <a name="-ipmi--snmp--lan_channel"></a>`lan_channel`

Data type: `Integer`
Data type: `Optional[Integer]`

Controls the lan channel of the IPMI network on which snmp is to be configured.
Defaults to the first detected lan channel, starting at 1 ending at 11

Default value: `$facts['ipmi']['default']['channel']`
Default value: `undef`

### <a name="ipmi--user"></a>`ipmi::user`

Expand Down Expand Up @@ -254,10 +263,10 @@ Default value: `undef`

##### <a name="-ipmi--user--channel"></a>`channel`

Data type: `Integer`
Data type: `Optional[Integer]`

Controls the channel of the IPMI user to be configured.
Defaults to the first detected lan channel, starting at 1 ending at 11

Default value: `$facts['ipmi']['default']['channel']`
Default value: `undef`

3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# `ipmi::user` resources to create.
# @param networks
# `ipmi::network` resources to create.
# @param default_channel
# Default channel to use for IPMI commands.
#
class ipmi (
Array[String] $packages,
Expand All @@ -33,6 +35,7 @@
Optional[Hash] $snmps,
Optional[Hash] $users,
Optional[Hash] $networks,
Integer[0] $default_channel = Integer(fact('ipmi.default.channel') or 1),
) {
$enable_ipmi = $service_ensure ? {
'running' => true,
Expand Down
51 changes: 28 additions & 23 deletions manifests/network.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,52 @@
# Defaults to the first detected lan channel, starting at 1 ending at 11
#
define ipmi::network (
Stdlib::IP::Address $ip = '0.0.0.0',
Stdlib::IP::Address $netmask = '255.255.255.0',
Stdlib::IP::Address $gateway = '0.0.0.0',
Enum['dhcp', 'static'] $type = 'dhcp',
Integer $lan_channel = $facts['ipmi']['default']['channel'],
Stdlib::IP::Address $ip = '0.0.0.0',
Stdlib::IP::Address $netmask = '255.255.255.0',
Stdlib::IP::Address $gateway = '0.0.0.0',
Enum['dhcp', 'static'] $type = 'dhcp',
Optional[Integer] $lan_channel = undef
) {
require ipmi::install

$_real_lan_channel = $lan_channel ? {
undef => $ipmi::default_channel,
default => $lan_channel,
}

if $type == 'dhcp' {
exec { "ipmi_set_dhcp_${lan_channel}":
command => "/usr/bin/ipmitool lan set ${lan_channel} ipsrc dhcp",
onlyif => "/usr/bin/test $(ipmitool lan print ${lan_channel} | grep 'IP \
exec { "ipmi_set_dhcp_${_real_lan_channel}":
command => "/usr/bin/ipmitool lan set ${_real_lan_channel} ipsrc dhcp",
onlyif => "/usr/bin/test $(ipmitool lan print ${_real_lan_channel} | grep 'IP \
Address Source' | cut -f 2 -d : | grep -c DHCP) -eq 0",
}
} else {
exec { "ipmi_set_static_${lan_channel}":
command => "/usr/bin/ipmitool lan set ${lan_channel} ipsrc static",
onlyif => "/usr/bin/test $(ipmitool lan print ${lan_channel} | grep 'IP \
exec { "ipmi_set_static_${_real_lan_channel}":
command => "/usr/bin/ipmitool lan set ${_real_lan_channel} ipsrc static",
onlyif => "/usr/bin/test $(ipmitool lan print ${_real_lan_channel} | grep 'IP \
Address Source' | cut -f 2 -d : | grep -c DHCP) -eq 1",
notify => [
Exec["ipmi_set_ipaddr_${lan_channel}"],
Exec["ipmi_set_defgw_${lan_channel}"],
Exec["ipmi_set_netmask_${lan_channel}"],
Exec["ipmi_set_ipaddr_${_real_lan_channel}"],
Exec["ipmi_set_defgw_${_real_lan_channel}"],
Exec["ipmi_set_netmask_${_real_lan_channel}"],
],
}

exec { "ipmi_set_ipaddr_${lan_channel}":
command => "/usr/bin/ipmitool lan set ${lan_channel} ipaddr ${ip}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${lan_channel} | grep \
exec { "ipmi_set_ipaddr_${_real_lan_channel}":
command => "/usr/bin/ipmitool lan set ${_real_lan_channel} ipaddr ${ip}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${_real_lan_channel} | grep \
'IP Address ' | sed -e 's/.* : //g')\" != \"${ip}\"",
}

exec { "ipmi_set_defgw_${lan_channel}":
command => "/usr/bin/ipmitool lan set ${lan_channel} defgw ipaddr ${gateway}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${lan_channel} | grep \
exec { "ipmi_set_defgw_${_real_lan_channel}":
command => "/usr/bin/ipmitool lan set ${_real_lan_channel} defgw ipaddr ${gateway}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${_real_lan_channel} | grep \
'Default Gateway IP' | sed -e 's/.* : //g')\" != \"${gateway}\"",
}

exec { "ipmi_set_netmask_${lan_channel}":
command => "/usr/bin/ipmitool lan set ${lan_channel} netmask ${netmask}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${lan_channel} | grep \
exec { "ipmi_set_netmask_${_real_lan_channel}":
command => "/usr/bin/ipmitool lan set ${_real_lan_channel} netmask ${netmask}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${_real_lan_channel} | grep \
'Subnet Mask' | sed -e 's/.* : //g')\" != \"${netmask}\"",
}
}
Expand Down
15 changes: 10 additions & 5 deletions manifests/snmp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
# Defaults to the first detected lan channel, starting at 1 ending at 11
#
define ipmi::snmp (
String $snmp = 'public',
Integer $lan_channel = $facts['ipmi']['default']['channel'],
String $snmp = 'public',
Optional[Integer] $lan_channel = undef,
) {
require ipmi::install

exec { "ipmi_set_snmp_${lan_channel}":
command => "/usr/bin/ipmitool lan set ${lan_channel} snmp ${snmp}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${lan_channel} | grep 'SNMP Community String' | sed -e 's/.* : //g')\" != \"${snmp}\"",
$_real_lan_channel = $lan_channel ? {
undef => $ipmi::default_channel,
default => $lan_channel,
}

exec { "ipmi_set_snmp_${_real_lan_channel}":
command => "/usr/bin/ipmitool lan set ${_real_lan_channel} snmp ${snmp}",
onlyif => "/usr/bin/test \"$(ipmitool lan print ${_real_lan_channel} | grep 'SNMP Community String' | sed -e 's/.* : //g')\" != \"${snmp}\"",
}
}
27 changes: 16 additions & 11 deletions manifests/user.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@
# Defaults to the first detected lan channel, starting at 1 ending at 11
#
define ipmi::user (
String $user = 'root',
Integer $priv = 4,
Boolean $enable = true,
Integer $user_id = 3,
String $user = 'root',
Integer $priv = 4,
Boolean $enable = true,
Integer $user_id = 3,
Optional[Variant[Sensitive[String[1]], String[1]]] $password = undef,
Integer $channel = $facts['ipmi']['default']['channel'],
Optional[Integer] $channel = undef,
) {
require ipmi::install

$_real_channel = $channel ? {
undef => $ipmi::default_channel,
default => $channel,
}

if $enable {
if empty($password) {
fail("You must supply a password to enable ${user} with ipmi::user")
Expand Down Expand Up @@ -97,18 +102,18 @@
}

exec { "ipmi_user_enable_sol_${title}":
command => "/usr/bin/ipmitool sol payload enable ${channel} ${user_id}",
command => "/usr/bin/ipmitool sol payload enable ${_real_channel} ${user_id}",
refreshonly => true,
}

exec { "ipmi_user_channel_setaccess_${title}":
command => "/usr/bin/ipmitool channel setaccess ${channel} ${user_id} callin=on ipmi=on link=on privilege=${priv}",
command => "/usr/bin/ipmitool channel setaccess ${_real_channel} ${user_id} callin=on ipmi=on link=on privilege=${priv}",
refreshonly => true,
}
} else {
exec { "ipmi_user_priv_${title}":
command => "/usr/bin/ipmitool user priv ${user_id} 0xF ${channel}",
unless => "/usr/bin/ipmitool user list ${channel} | grep -qE '^${user_id} .+ NO ACCESS$'",
command => "/usr/bin/ipmitool user priv ${user_id} 0xF ${_real_channel}",
unless => "/usr/bin/ipmitool user list ${_real_channel} | grep -qE '^${user_id} .+ NO ACCESS$'",
notify => [Exec["ipmi_user_disable_${title}"], Exec["ipmi_user_disable_sol_${title}"], Exec["ipmi_user_channel_setaccess_${title}"]],
}

Expand All @@ -118,12 +123,12 @@
}

exec { "ipmi_user_disable_sol_${title}":
command => "/usr/bin/ipmitool sol payload disable ${channel} ${user_id}",
command => "/usr/bin/ipmitool sol payload disable ${_real_channel} ${user_id}",
refreshonly => true,
}

exec { "ipmi_user_channel_setaccess_${title}":
command => "/usr/bin/ipmitool channel setaccess ${channel} ${user_id} callin=off ipmi=off link=off privilege=15",
command => "/usr/bin/ipmitool channel setaccess ${_real_channel} ${user_id} callin=off ipmi=off link=off privilege=15",
refreshonly => true,
}
}
Expand Down

0 comments on commit 5b681e6

Please sign in to comment.