Forum: CFEngine Help
Subject: Re: variables changing between passes
Author: phnakarin
Link to topic: https://cfengine.com/forum/read.php?3,22924,22933#msg-22933

I spotted errors on your code. For example, repair_failed and promise_repaired 
are not allowed in commands stanza but classes body.
http://cfengine.com/manuals/cf3-reference.html#classes-in-_002a

Try this code if you don't mind. It should do what you want. I just played 
around with classes

bundle agent app_db_mysql_mycnf
{
vars:
    "mycnf" string =>  "root/.my.cnf";

    "newpass" string => execresult("/usr/bin/makepasswd --chars 12","noshell"),
              policy => "constant",
              ifvarclass => "no_newpass";

classes:
    "no_newpass" not => isvariable("no_newpass");

commands:
    "/usr/bin/mysqladmin status"   # if a password is null, promise will be 
repaired #
         handle => "check_mysql_root_pwd",
        comment => "Check mysql root password",
        contain => in_shell,
        classes => 
if_repaired_then_cancel("set_mysql_root_from_null","no_newpass");

 set_mysql_root_from_null::
    "/usr/bin/mysqladmin --password= password $(newpass)"
         handle => "set_mysql_root_from_null",
        comment => "Set Mysql root password if it is null to $(newpass)",
        contain => in_shell,
        classes => 
if_repaired_then_cancel("update_mycnf","set_mysql_root_from_null");

files:
 update_mycnf::
   "/$(mycnf)"
      handle => "update_mycnf",
     comment => "Add the new password to my_cnf",
       perms => mog("0600", "root", "root"),
   edit_line => section_config("client","password","$(newpass)");
}

body classes if_repaired_then_cancel(xxx,yyy)
{
 promise_repaired => { "$(xxx)" };
 cancel_repaired => { "$(yyy)" };
} 


Cheers,
--Nakarin

_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to