Don't try to call shell commands, use the exit status of a "packages" promise otherwise you are just writing a shell script and you lose all the optimizations. I don't have time to come up with an example right now, but perhaps this will push you in the right direction.
Andrew J. Millar wrote: > Greetings all > > I'm struggling with a cfengine recipe - my goal is to check an slist of RPMs > to > see if they are installed, and install any missings ones. Alas, if at least > one > of the RPMs is installed, the class check fails, and the missings RPMS are not > installed. If all of the RPMS are missing, then the class check passes and the > RPMS are installed. > > In this example, I'm checking for the presence of rpm-build and createrepo > > Here is my setup: > cf-agent --version > This comprises cf-agent core community version 3.0.3 - (C) Cfengine AS 2008- > (svn build) > > body common control > > { > bundlesequence => { "checkrpms" }; > } > > > bundle agent checkrpms > { > vars: > "rpms_needed" slist => { "rpm-build", "createrepo" }, > comment => "List of required RPMs"; > > classes: > "rpms_installed" expression => returnszero("/bin/rpm -q > $(rpms_needed)","noshell"), > comment => "Check if required rpms are installed"; > > commands: > !rpms_installed:: > "/usr/bin/yum -q -y install $(rpms_needed)", > comment => "Installing $(rpms_needed)"; > } > > If I uninstall createrepo and run the recipe, this is the output: > # cf-agent -I -f ./check_rpms.cf > rpm-build-4.4.2.3-18.el5 > package createrepo is not installed > rpm-build-4.4.2.3-18.el5 > package createrepo is not installed > rpm-build-4.4.2.3-18.el5 > package createrepo is not installed > # > > If I uninstall both createrepo and rpm-build, the output is: > # cf-agent -I -f ./check_rpms.cf > package rpm-build is not installed > package createrepo is not installed > -> Executing '/usr/bin/yum -q -y install rpm-build' > ...(timeout=-678,owner=-1,group=-1) > -> Completed execution of /usr/bin/yum -q -y install rpm-build > -> Executing '/usr/bin/yum -q -y install createrepo' > ...(timeout=-678,owner=-1,group=-1) > -> Completed execution of /usr/bin/yum -q -y install createrepo > rpm-build-4.4.2.3-18.el5 > createrepo-0.4.11-3.el5 > rpm-build-4.4.2.3-18.el5 > createrepo-0.4.11-3.el5 > # > > Can anyone help me tweak the recipe to install the missing RPM if either are > not installed? > > Many thanks > > Kind regards > Andrew > > > > Shop spring’s building blocks at NET-A-PORTER.COM > ______________________________________________________________________ > > CONFIDENTIALITY NOTICE > The information in this email is confidential and is intended solely for the > addressee. Access to this email by anyone else is unauthorised. If you are > not the intended recipient, you must not read, use or disseminate the > information. Any views expressed in this message are those of the individual > sender, except where the sender specifically states them to be the views of > Net a Porter Ltd. > > Net A Porter Ltd is a company registered in England & Wales Number: 3820604 > Registered Office: The Dome, Whiteleys Centre, 151 Queensway, London, W2 4YN. > _____________________________________________________________________ > _______________________________________________ > Help-cfengine mailing list > Help-cfengine@cfengine.org > https://cfengine.org/mailman/listinfo/help-cfengine -- Mark Burgess ------------------------------------------------- Professor of Network and System Administration Oslo University College, Norway Personal Web: http://www.iu.hio.no/~mark Office Telf : +47 22453272 ------------------------------------------------- _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine