I would like to avoid (or hide at least) "failed dependencies" logs on puppet.
I want to deploy files only if exec requirement are true. It's working but puppet shows a lot of err/warning logs :
Error: /usr/bin/test -e /home/USER returned 1 instead of one of [0]
Error: /Stage[main]/Users::Config/Exec[/usr/bin/test -e /home/USER]/returns: change from notrun to 0 failed: /usr/bin/test -e /home/USER returned 1 instead of one of [0]
Notice: /Stage[main]/Users::Config/Exec[check_ssh_dir]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/Exec[check_ssh_dir]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.ssh]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.ssh]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.bashrc]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.bashrc]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.bash_profile]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.bash_profile]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.ssh/authorized_keys]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.ssh/authorized_keys]: Skipping because of failed dependencies
Here is my config.pp :
class users::config ($user) {
exec {"/usr/bin/test -e /home/${user}":
}
exec {"check_ssh_dir":
command => '/bin/true',
onlyif => "/usr/bin/test -e /home/${user}/.ssh",
require => Exec["/usr/bin/test -e /home/${user}"],
}
file {"/home/${user}/.ssh":
ensure => directory,
owner => "${user}",
group => "domain users",
mode => "700",
require => Exec['check_ssh_dir'],
}
file {"/home/${user}/.bashrc":
source => [ "puppet:///modules/users/${user}/bashrc", "puppet:///modules/users/basics/bashrc"],
owner => "${user}",
group => "domain users",
mode => "640",
require => Exec["/usr/bin/test -e /home/${user}"],
}
file {"/home/${user}/.bash_profile":
source => [ "puppet:///modules/users/${user}/bash_profile", "puppet:///modules/users/basics/bash_profile"],
owner => "${user}",
group => "domain users",
mode => "640",
require => Exec["/usr/bin/test -e /home/${user}"],
}
file {"/home/${user}/.ssh/authorized_keys":
source => [ "puppet:///modules/users/${user}/ssh/authorized_keys", "puppet:///modules/users/basics/ssh/authorized_keys"],
owner => "${user}",
group => "domain users",
mode => "600",
require => Exec["check_ssh_dir"],
}
}
I'm using puppet 4.3.
Thanks for helping.
This is not really possible without using facts or implementing a custom provider. To be sure, with
exec
resources you can do something like this:But you won't be able to have conditional
file
resources on the result of the a command. The easiest option is to create a fact. Something like:Then you could check if
$user
was in the array$::avail_users
in anif
block. Make sure you don't havestringify_facts
on.I have found how to solve my issue thanks to @Artefacto :
I have created a new fact which just list homes :
And I have modified my manifest to iterate on each home :
Now I have no failed due to dependencies.