No, it works. grep returns false if the regex doesn't match anything (or if there's a processing error), see "exit status" in grep man page. The exec will only run if stdout of the mysql command contains a line with only a 0 in it. Mysql doesn't allow 0 as a table name and error messages are printed to stderr (and I've removed the redirect to stdout, puppet prints the stderr of onlyif commands if you run it with --debug). So, you only get a 0 in the mysql output if the database exists and there are no tables in the database.