Skip to content

Commit

Permalink
Make the main service and package available under the application's name
Browse files Browse the repository at this point in the history
This allows the following usage:

```
tp::install { exim: }

Package[exim] -> File['extra conf'] ~> Service[exim]
```

without having to know anything about the underlying OS and data, when
tp::conf and tp::dir do not suffice.
  • Loading branch information
DavidS committed Mar 27, 2016
1 parent fee3ac8 commit af5c64b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ If, for whatever reason, you don't want to automatically manage a repository for
}


### Custom Dependencies

In rare cases it might be necessary to have a relationship in between the parts of a `tp::install`. To allow this, the main package and service resource are available under the name of the application:

```
tp::install { exim: }
Package[exim] -> Exec['extra setup script'] ~> Service[exim]
```

This works even if, like in this case, the package and service names vary widely across distributions.


## Usage with Hiera

You may find useful the ```create_resources``` defines that are feed, in the main ```tp``` class by special ```hiera_hash``` lookups that map all the available ```tp``` defines to hiera keys in this format ```tp::<define>_hash```.
Expand Down
32 changes: 25 additions & 7 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
if $settings[package_name] == Variant[Undef,String[0]] {
$service_require = undef
} else {
$service_require = Package[$settings[package_name]]
$service_require = Package[$name]
}

$service_ensure = $ensure ? {
Expand Down Expand Up @@ -139,19 +139,37 @@
if $settings[package_name] {
$packages_array=any2array($settings[package_name])
$packages_array.each |$pkg| {
package { $pkg:
ensure => $ensure,
# Setup a stable alias to the application's name for the "main" package
if $pkg != $name and (size($packages_array) == 1 or $svc == $settings[main_package]) {
package { $name:
name => $pkg,
ensure => $ensure,
}
} else {
package { $pkg:
ensure => $ensure,
}
}
}
}

if $settings[service_name] {
$services_array=any2array($settings[service_name])
$services_array.each |$svc| {
service { $svc:
ensure => $service_ensure,
enable => $service_enable,
require => $service_require,
# Setup a stable alias to the application's name for the "main" service
if $svc != $name and (size($services_array) == 1 or $svc == $settings[main_service]) {
service { $name:
name => $svc,
ensure => $service_ensure,
enable => $service_enable,
require => $service_require,
}
} else {
service { $svc:
ensure => $service_ensure,
enable => $service_enable,
require => $service_require,
}
}
}
}
Expand Down

0 comments on commit af5c64b

Please sign in to comment.