CFEngine 3新手在这里。

我想在Ubuntu系统上安装Oracle JDK,如何在CFEngine中编写脚本?

我可以使用webupd8team提供的PPA在Shell中执行以下操作:

add-apt-repository ppa:webupd8team/java
apt-get update

echo "Installing JDK 7..."
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
apt-get install -y oracle-java7-installer


在CFEngine中完全没有这样做。到目前为止,我有:

body common control {
    inputs => { "$(sys.libdir)/stdlib.cf" };
    bundlesequence => { "manage_properties",
                        "manage_jdk"};
}

bundle agent manage_properties {
    vars:
        "prop_pkgs" slist => {"python-software-properties", "software-properties-common"};
        "cmds"      slist => {  "/usr/bin/add-apt-repository ppa:webupd8team/java",
                                "/bin/echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections",
                                "/bin/echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections",
                                "/usr/bin/apt-get update" };

    methods:
        "$(prop_pkgs)"
            handle => "manage_properties",
            comment => "Make sure required properties packages are installed",
            usebundle => package_latest("$(prop_pkgs)");

    commands:
        "$(cmds)"
            comment => "Firing preinstall commands for JDK";
}

bundle agent manage_jdk {
    methods:
        "JDK"
            handle => "manage_jdk",
            comment => "Make sure Java is installed",
            usebundle => package_latest("oracle-java7-installer");
}


但是诺言失败,并出现以下错误:

2014-06-30T14:11:18+0000    error: /default/manage_jdk/methods/'JDK'/default/package_latest/packages/'oracle-java7-installer'[0]: Finished command related to promiser 'oracle-java7-installer' -- an error occurred, returned 100
2014-06-30T14:11:18+0000    error: /default/manage_jdk/methods/'JDK'/default/package_latest/packages/'oracle-java7-installer'[0]: Bulk package schedule execution failed somewhere - unknown outcome for 'oracle-java7-installer'


将不胜感激任何指针。谢谢

最佳答案

我在您的策略中看到的一件事是,您正在运行一些需要外壳程序的命令(您的管道命令),并且您的命令承诺不会包含在任何外壳程序中。

commands: "/bin/echo 'Hello World' | grep Hello" contain => in_shell;

另外,您似乎对预命令的看法非常必要。 CFEngine通常每5分钟运行一次策略。我将更多地集中在必要时执行必要的操作,并尝试着重于状态而不是操作。

例如,您无条件运行apt-add-repository。考虑在什么条件下您实际需要执行命令。

09-25 21:19