{"record":{"id":"e972396106dd84f3","repo":"puppetlabs/puppet","slug":"could-not-action-name-output","errorCode":null,"errorMessage":"Could not #{action} #{name}: #{output}","messagePattern":"Could not #(.+?) #(.+?): #(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/service/systemd.rb","lineNumber":77,"sourceCode":"        true\n      end\n    when 'indirect'\n      Puppet.debug(\"Service #{@resource[:name]} is in 'indirect' state and cannot be enabled/disabled\")\n      true\n    else\n      current == @resource[:enable]\n    end\n  end\n\n  # This helper ensures that the enable state cache is always reset\n  # after a systemctl enable operation. A particular service state is not guaranteed\n  # after such an operation, so the cache must be emptied to prevent inconsistencies\n  # in the provider's believed state of the service and the actual state.\n  # @param action [String,Symbol] One of 'enable', 'disable', 'mask' or 'unmask'\n  def systemctl_change_enable(action)\n    output = systemctl(action, '--', @resource[:name])\n  rescue => e\n    raise Puppet::Error, \"Could not #{action} #{name}: #{output}\", e.backtrace\n  ensure\n    @cached_enabled = nil\n  end\n\n  def disable\n    systemctl_change_enable(:disable)\n  end\n\n  def get_start_link_count\n    # Start links don't include '.service'. Just search for the service name.\n    if @resource[:name] =~ /\\.service/\n      link_name = @resource[:name].split('.')[0]\n    else\n      link_name = @resource[:name]\n    end\n\n    Dir.glob(\"/etc/rc*.d/S??#{link_name}\").length\n  end","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/service/systemd.rb#L59-L95","documentation":"The systemd provider routes enable/disable/mask/unmask through systemctl_change_enable, which runs systemctl <action> -- <name> and converts any raised exception into Puppet::Error (the interpolated output is nil on the failure path because the assignment never completed). An ensure block always clears @cached_enabled, since post-command state is not guaranteed and a stale cache would corrupt the provider's believed state.","triggerScenarios":"systemctl enable/disable/mask/unmask exiting non-zero: the unit file does not exist (enable on a never-installed unit), the unit was just installed but systemd was not daemon-reloaded, running inside a container/chroot where systemd is not PID 1, or a read-only /etc (read-only bind mounts, atomic/immutable hosts).","commonSituations":"Missing Package/File -> Service ordering so enable runs before the unit lands; modules dropping unit files without a systemctl daemon-reload; docker exec / chroot puppet runs; /usr or /etc mounted read-only (Silverblue-style) blocking symlink creation in /etc/systemd/system.","solutions":["Reproduce exactly: systemctl enable -- <name> and read its stderr (usually 'Unit <name>.service does not exist')","Order unit installation first, and add a daemon-reload exec with refreshonly between the unit file and the service resource","Confirm the unit is visible: systemctl list-unit-files | grep <name> and systemctl cat <name>","In containers/chroots, don't manage systemd enablement — skip the service resource or run puppet on the host, not inside the namespace"],"exampleFix":"# before\nfile { '/etc/systemd/system/myapp.service': source => 'puppet:///modules/app/myapp.service' }\nservice { 'myapp': ensure => running, enable => true }\n\n# after\nfile { '/etc/systemd/system/myapp.service':\n  source  => 'puppet:///modules/app/myapp.service',\n  notify  => Exec['myapp-daemon-reload'],\n}\nexec { 'myapp-daemon-reload':\n  command     => '/usr/bin/systemctl daemon-reload',\n  refreshonly => true,\n}\n-> service { 'myapp': ensure => running, enable => true }","handlingStrategy":"validation","validationCode":"# the unit must exist and be loaded before enable/disable/mask\nsystemctl cat \"${name}\" >/dev/null 2>&1 || echo \"unit missing — install it and 'systemctl daemon-reload' first\"\nsystemctl list-unit-files | grep -q \"^${name}\" || echo \"unit file not registered; daemon-reload required\"","typeGuard":null,"tryCatchPattern":"begin\n  provider.enable\nrescue Puppet::Error => e\n  # output is nil on this path; run 'systemctl enable -- #{name}' by hand for the real error\n  warn \"systemctl enable failed for #{name}: #{e.message}\"\nend","preventionTips":["Always chain unit-file installation -> daemon-reload exec (refreshonly) -> service resource","Never run enable-management inside containers/chroots where systemd is not PID 1; scope such resources by facts","On read-only-/etc hosts, handle unit enablement via the image/preset layer rather than systemctl at runtime","After adding units, validate with systemctl list-unit-files in acceptance tests"],"tags":["puppet","systemd","systemctl","service","enable"],"backgroundTag":"command-execution-failure","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}