Skip to content

Instantly share code, notes, and snippets.

@kreczko
Last active December 19, 2015 01:39
Show Gist options
  • Save kreczko/5877191 to your computer and use it in GitHub Desktop.
Save kreczko/5877191 to your computer and use it in GitHub Desktop.
Code for exec with onlyif example
exec { 'create-apel-mysql-tables':
command => '/usr/bin/mysql --defaults-file=/root/.my.cnf apelclient < /usr/share/apel/client.sql',
require => [
File['/usr/share/apel/client.sql'],
Class["mysql"],
Class["mysql::server"],
Database[$mysql_database]],
# needs check if already exists, otherwise will wipe the tables!
onlyif => 'exit $(`/usr/bin/mysql --defaults-file=/root/.my.cnf -e "use apelclient; show tables;SELECT FOUND_ROWS();" 2>&1 | cut -f1 | egrep "^(0|[1-9][0-9]*)$"`)'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment