Назад | Перейти на главную страницу

Как скрыть журналы «неудачных зависимостей» на марионетке

Я хотел бы избежать (или, по крайней мере, скрыть) журналы «неудачных зависимостей» на марионетке.

Я хочу развертывать файлы только в том случае, если требования exec верны. Он работает, но марионетка показывает много журналов ошибок / предупреждений:

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

Вот мой 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"],
    }
}

Я использую марионетку 4.3.

Спасибо за помощь.

На самом деле это невозможно без использования фактов или реализации настраиваемого поставщика. Конечно, с exec ресурсы можно сделать примерно так:

exec { 'test-user-exists:
    command => '/bin/true',
    onlyif  => "/usr/bin/test -e /home/${user}"
} ~>
exec { 'conditional-command':
    command     => '/usr/bin/my-command',
    refreshonly => true,
}

Но вы не сможете иметь условное file ресурсы по результату выполнения команды. Самый простой вариант - констатировать факт. Что-то вроде:

Facter.add(:avail_users) do
  setcode do
    IO.
      readlines('/etc/passwd').
      map { |x| x.split(':')[0] }
  end
end

Тогда вы можете проверить, есть ли $user был в массиве $::avail_users в if блок. Убедитесь, что у вас нет stringify_facts на.

Я нашел, как решить свою проблему, благодаря @Artefacto:

Я создал новый факт, который просто перечисляет дома:

Facter.add(:list_home) do
    setcode do
        Facter::Core::Execution.exec('/bin/ls /home/').split("\n")
    end
end

И я изменил свой манифест, чтобы перебирать каждый дом:

class users::config {

    $::list_home.each |String $user| {
        exec {"check_ssh_dir_${user}":
            command => '/bin/true',
            onlyif => "/usr/bin/test -e /home/${user}/.ssh",
        }

        file {"/home/${user}/.ssh":
            ensure => directory,
            owner   => "${user}",
                    group   => "domain users",
                    mode    => "700",
            require => Exec["check_ssh_dir_${user}"],
        }

        file {"/home/${user}/.bashrc":
            source => [ "puppet:///modules/users/${user}/bashrc", "puppet:///modules/users/basics/bashrc"],
            owner   => "${user}",
            group   => "domain users",
            mode    => "640",
        }

        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",
        }

        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",
        }
    }
}

Теперь у меня нет сбоев из-за зависимостей.