AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 759578
Accepted
Skullone
Skullone
Asked: 2016-02-25 13:12:49 +0800 CST2016-02-25 13:12:49 +0800 CST 2016-02-25 13:12:49 +0800 CST

如何在 puppet 上隐藏“失败的依赖项”日志

  • 772

我想避免(或至少隐藏)木偶上的“失败的依赖项”日志。

只有当 exec 要求为真时,我才想部署文件。它正在工作,但 puppet 显示了很多错误/警告日志:

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。

感谢您的帮助。

puppet
  • 2 2 个回答
  • 862 Views

2 个回答

  • Voted
  1. Artefacto
    2016-02-27T01:46:55+08:002016-02-27T01:46:55+08:00

    如果不使用事实或实现自定义提供程序,这实际上是不可能的。可以肯定的是,使用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,
    }
    

    但是您将无法根据filea 命令的结果获得条件资源。最简单的选择是创建一个事实。就像是:

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

    然后你可以检查是否在一个块$user的数组中。确保你没有。$::avail_usersifstringify_facts

    • 2
  2. Best Answer
    Skullone
    2016-03-01T12:33:10+08:002016-03-01T12:33:10+08:00

    感谢@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",
            }
        }
    }
    

    现在我没有因为依赖而失败。

    • 0

相关问题

  • 如何修复 Puppet 完全限定的参数路径错误?

  • puppet:修改配置文件后强制重启服务

  • 木偶模块资源

  • 傀儡主机名问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve