Skip to content

Commit

Permalink
Lints and psick::tools::create_dir windows compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
alvagante committed Oct 18, 2023
1 parent b1daa14 commit df00da5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- More updates for Puppet 8 compatibility
- Added psick::puppet::facter profile to manage facter.conf
- pdk update
- Make psick::tools::create_dir windows compatible

## Release 1.0.4

Expand Down
2 changes: 1 addition & 1 deletion manifests/hosts/file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class psick::hosts::file (
String $template = 'psick/hosts/file/hosts.erb',

Optional[Stdlib::Compat::Ip_address] $ipaddress = $psick::primary_ip,
Optional[Stdlib::IP::Address] $ipaddress = $psick::primary_ip,
Variant[Undef,String] $domain = $facts['networking']['domain'],
String $hostname = $facts['networking']['hostname'],
Array $extra_hosts = [],
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
Boolean $noop_value = false,

# General network settings
Optional[Stdlib::Compat::Ip_address] $primary_ip = fact('networking.ip'),
Optional[Stdlib::IP::Address] $primary_ip = fact('networking.ip'),
Optional[String] $mgmt_interface = fact('networking.primary'),
Optional[String] $timezone = undef,
Hash $interfaces_hash = {},
Expand Down
4 changes: 2 additions & 2 deletions manifests/network/netplan/interface.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
Optional[Stdlib::MAC] $macaddress = getvar("networking.interfaces.${interface_name}.mac"),
Variant[Undef,Psick::Network::NetplanAddresses] $addresses = undef,
Variant[Undef,Array] $routes = undef,
Optional[Stdlib::Compat::Ipv4] $gateway4 = undef,
Optional[Stdlib::Compat::Ipv6] $gateway6 = undef,
Optional[Stdlib::IP::Address::V4] $gateway4 = undef,
Optional[Stdlib::IP::Address::V6] $gateway6 = undef,
Optional[Hash] $nameservers = undef,
Optional[Hash] $parameters = undef,

Expand Down
58 changes: 36 additions & 22 deletions manifests/tools/create_dir.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,45 @@
Optional[String] $mode = undef,
Stdlib::AbsolutePath $path = $title,
) {
exec { "mkdir -p ${title}":
command => "mkdir -p ${path}",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
creates => $path,

$mkdir_command = $facts['os']['family'] ? {
'windows' => "New-Item -ItemType Directory -Force -Path '${path}'",
default => "mkdir -p '${path}'",
}
if $owner {
exec { "chown ${owner} ${title}":
command => "chown ${owner} ${path}",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
onlyif => "[ $(ls -ld ${path} | awk '{ print \$3 }') != ${owner} ]",
}
$command_provider = $facts['os']['family'] ? {
'windows' => 'powershell',
default => undef,
}
if $group {
exec { "chgrp ${group} ${title}":
command => "chgrp ${group} ${path}",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
onlyif => "[ $(ls -ld ${path} | awk '{ print \$4 }') != ${group} ]",
}

exec { "Create directory ${title}":
command => $mkdir_command,
path => $facts['path'],
creates => $path,
provider => $command_provider,
}
if $mode {
exec { "chmod ${mode} ${title}":
command => "chmod ${mode} ${path}",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
subscribe => Exec["mkdir -p ${title}"],
refreshonly => true,

if $facts['os']['family'] != 'windows' {
if $owner {
exec { "chown ${owner} ${title}":
command => "chown '${owner}' '${path}'",
path => $facts['path'],
onlyif => "[ stat -c '%U' '${path}' != '${owner}' ]",
}
}
if $group {
exec { "chgrp ${group} ${title}":
command => "chgrp '${group}' '${path}'",
path => $facts['path'],
onlyif => "[ stat -c '%G' '${path}' != '${group}' ]",
}
}
if $mode {
exec { "chmod ${mode} ${title}":
command => "chmod '${mode}' '${path}'",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
subscribe => Exec["Create directory ${title}"],
refreshonly => true,
}
}
}
}

0 comments on commit df00da5

Please sign in to comment.