}
That is the general form you would want to use with create_resources() and a definition along these lines:
define database::user ( $password, $userpermissions ) {
exec { "db_user_${title}":
command => "echo \"CREATE ROLE ${title} WITH ${userpermissions} PASSWORD '${password}';\"| psql",
unless => "echo '\\dg' | psql | grep -q ${title}"
}
}
Alternatively, there are sometimes reasons to prefer explicit resource declarations over create_resources(). With the same (revised) form of the data, you could also do this:
$db_usernames = keys($database_users)
database::user2 { $db_usernames:
userdata => $database_users
}
with a slightly different definition:
define database::user2 ( $all_data ) {
$data = $all_data[$title]
exec { "db_user_${title}":
command => "echo \"CREATE ROLE ${title} WITH ${data['userpermissions']} PASSWORD '${data['password']}';\"| psql",
unless => "echo '\\dg' | psql | grep -q ${title}"
}
}
Alternatively, if the top user data hash is in a class variable somewhere, then you can consider skipping passing it as a parameter, and let the definition instead access it directly.
John