Add template support to `systemd_unit`
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.5k
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 23
Description
Creating from #11402
Describe the Enhancement:
I would like to be able to specify a template (and required configurations) when defining a systemd unit file with systemd_unit.
Describe the Need:
When dealing with complex systemd unit files within a custom resource, it would be useful to be able to expose the ability to override the contents via a template file rather than a string or hash.
In the instance of sous-chefs/tomcat since we are providing a unit file with sensible defaults and expose the ability to override that template to the user, we cannot currently utilize the systemd_unit resource and instead fall back to managing the unit file directly with template and interacting with systemd with execute
https://github.com/sous-chefs/tomcat/pull/358#discussion_r492897903
Current Alternative
As demonstrated in the above cookbook, we are managing the unit file directly with template rather than utilizing the systemd_unit resource.
Can We Help You Implement This?:
This is a reasonable request or does it add too much complexity to the resource?
In terms of implementation, I was thinking something like the following.
Addition of properties such as these added to systemd_unit:
property :template_source, String,
description: "The location of a template file. By default, #{ChefUtils::Dist::Infra::CLIENT} looks for a template file in the /templates directory of a cookbook."
property :template_cookbook, [String, Hash],
description: "The cookbook in which a file is located (if it is not located in the current cookbook). The default value is the current cookbook.",
desired_state: false
property :template_variables, [String, Hash],
description: "The variables property of the template resource can be used to reference a partial template file by using a Hash.",
default: {}
property :template_local, [ TrueClass, FalseClass ],
default: false, desired_state: false,
description: "Load a template from a local path. By default, the #{ChefUtils::Dist::Infra::CLIENT} loads templates from a cookbook's /templates directory. When this property is set to true, use the source property to specify the path to a template on the local node."
From there I believe there just needs to be logic within manage_unit_file to detect content usage vs template_source and then use the template resource from there.
https://github.com/chef/chef/blob/master/lib/chef/provider/systemd_unit.rb#L259
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/chef/provider/systemd_unit.rb at manage_unit_file, then review the proposed template properties and the existing systemd_unit resource behavior. Done means systemd_unit supports template-based unit contents and required template configuration alongside its current content options, with behavior suitable for the tomcat use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100