diff --git a/ntp/ng/init.sls b/ntp/ng/init.sls index de7e08f..c00eae7 100644 --- a/ntp/ng/init.sls +++ b/ntp/ng/init.sls @@ -26,8 +26,14 @@ ntpd_conf: {% endif %} {% if 'ntpd' in ntp.settings %} +{% set service_state = service.get(ntp.settings.ntpd) %} +{# Do not attempt to run the service in a container where the service is configured with #} +{# `ConditionVirtualization=!container` or similar (e.g. via. `kitchen-salt`) #} +{% if grains.os_family in ['Suse'] and salt['config.get']('virtual_subtype', '') in ['Docker'] %} +{% set service_state = 'dead' %} +{% endif %} ntpd: - service.{{ service.get(ntp.settings.ntpd) }}: + service.{{ service_state }}: - name: {{ ntp.lookup.service }} - enable: {{ ntp.settings.ntpd }} {%- if 'init_delay' in ntp.settings %} diff --git a/test/integration/default/controls/services_spec.rb b/test/integration/default/controls/services_spec.rb index ae807c3..de7c87c 100644 --- a/test/integration/default/controls/services_spec.rb +++ b/test/integration/default/controls/services_spec.rb @@ -8,13 +8,27 @@ 'ntpd' end -control 'ntp service' do +control 'ntp service (installed)' do impact 0.5 title 'should be installed and enabled' describe service(service_name) do it { should be_installed } it { should be_enabled } + end +end + +control 'ntp service (running)' do + impact 0.5 + title 'should be running' + only_if( + 'unable to run the service in a container due to its '\ + '`ConditionVirtualization` setting' + ) do + platform[:family] != 'suse' + end + + describe service(service_name) do it { should be_running } end end