Skip to content

Commit

Permalink
migrate from file resource to concat
Browse files Browse the repository at this point in the history
this allows us to use this defined type as often as we want (which is
the purpose of a defined type). Each usage of it creates an entry in
$user/.ssh/config. This is not a breaking change since you can still use
the resource as before. However, you can now call it multiple types by
setting a unique name for it + providing user => $user as a parameter.

Use case: define a block in each puppet profile you have.

Notice: I needed to bump the concat dependency by a major release, this
means that the next release of this software also should be a major one,
even if the API of this module has no breaking changes.
  • Loading branch information
bastelfreak committed Mar 1, 2017
1 parent 8c6c10e commit 1fbf6a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 20 additions & 13 deletions manifests/client/config/user.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
Hash $options = {},
Optional[Stdlib::Absolutepath] $target = undef,
Optional[Stdlib::Absolutepath] $user_home_dir = undef,
String $user = $name,
)
{

include ::ssh::params

$_files_ensure = $ensure ? { 'present' => 'file', 'absent' => 'absent' }

# If a specific target file was specified,
# it must have higher priority than any
# other parameter.
Expand All @@ -25,7 +24,7 @@
}
else {
if ($user_home_dir == undef) {
$_user_home_dir = "/home/${name}"
$_user_home_dir = "/home/${user}"
}
else {
validate_absolute_path($user_home_dir)
Expand All @@ -36,20 +35,28 @@
$_target = "${user_ssh_dir}/config"

if ($manage_user_ssh_dir == true) {
file { $user_ssh_dir:
ensure => directory,
owner => $name,
mode => $::ssh::params::user_ssh_directory_default_mode,
before => File[$_target],
unless defined(File[$user_ssh_dir]) {
file { $user_ssh_dir:
ensure => directory,
owner => $user,
mode => $::ssh::params::user_ssh_directory_default_mode,
before => Concat_file[$_target],
}
}
}
}

file { $_target:
ensure => $_files_ensure,
owner => $name,
mode => $::ssh::params::user_ssh_config_default_mode,
unless defined(Concat_file[$_target]) {
concat_file{$_target:
ensure => $ensure,
owner => $user,
mode => $::ssh::params::user_ssh_config_default_mode,
tag => $user,
}
}
concat_fragment{$name:
tag => $user,
content => template("${module_name}/ssh_config.erb"),
target => $_target,
}

}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
{
"name": "puppetlabs/concat",
"version_requirement": ">= 1.2.5 < 3.0.0"
"version_requirement": ">= 2.2.0 < 3.0.0"
}
]
}

0 comments on commit 1fbf6a7

Please sign in to comment.