imme
imme

Reputation: 319

CFEngine 3.5 Oracle JDK promise

CFEngine 3 newbie here.

Am trying to get Oracle JDK installed on an Ubuntu system, how should I script it in CFEngine?

I can do something like this in shell by using PPA provided by webupd8team:

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

Am totally lost doing this in CFEngine. So far I have:

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");
}

But the promise fails with following error:

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'

Would appreciate any pointer. Thanks

Upvotes: 2

Views: 234

Answers (1)

Nick Anderson
Nick Anderson

Reputation: 316

One thing that I see in your policy is that you are running some commands that require a shell (your piped commands) and your commands promise is not being contained within any shell.

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

Also, it seems that you are taking a very imperative view with your pre-commands. CFEngine typically runs policy once every 5 minutes. I would focus more on performing the operations necessary when necessary and try to focus on the state instead of action.

For example your running apt-add-repository unconditionally. Consider under what conditions you actually need to execute the command.

Upvotes: 1

Related Questions