From baaa2ede39ad7c751854497db595031f00c829dc Mon Sep 17 00:00:00 2001 From: Michael Watters Date: Wed, 7 Aug 2019 12:05:25 -0400 Subject: [PATCH] Set snmpd stop command based on the node's default service provider --- manifests/snmpv3_user.pp | 8 ++++---- spec/defines/snmp_snmpv3_user_spec.rb | 9 --------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/manifests/snmpv3_user.pp b/manifests/snmpv3_user.pp index 9e946ffc..4eb752e6 100644 --- a/manifests/snmpv3_user.pp +++ b/manifests/snmpv3_user.pp @@ -66,10 +66,10 @@ if $create { unless defined(Exec["stop-${service_name}"]) { - # - # TODO: update $command for different operating systems/releases - # - $command = "service ${service_name} stop ; sleep 5" + $command = $facts['service_provider'] ? { + 'systemd' => "systemctl stop ${service_name}; sleep 5", + default => "service ${service_name} stop ; sleep 5", + } exec { "stop-${service_name}": command => $command, diff --git a/spec/defines/snmp_snmpv3_user_spec.rb b/spec/defines/snmp_snmpv3_user_spec.rb index c7ccbb02..e732d855 100644 --- a/spec/defines/snmp_snmpv3_user_spec.rb +++ b/spec/defines/snmp_snmpv3_user_spec.rb @@ -21,7 +21,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -50,7 +49,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -77,7 +75,6 @@ it { is_expected.to contain_exec('stop-snmptrapd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmptrapd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -103,7 +100,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -132,7 +128,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -159,7 +154,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -185,7 +179,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -214,7 +207,6 @@ it { is_expected.to contain_exec('stop-snmpd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmpd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) @@ -241,7 +233,6 @@ it { is_expected.to contain_exec('stop-snmptrapd').with( path: '/bin:/sbin:/usr/bin:/usr/sbin', - command: 'service snmptrapd stop ; sleep 5', user: 'root' ).that_requires(['Package[snmpd]', 'File[var-net-snmp]'])