Как создать пользовательский сервис
Посмотрите эти вопросы.
Создайте задачу расписания, которая работает при начальной загрузке
Наконец, я обнаружил, что это проблема с переменной областью видимости, правильный init.pp
должен быть:
class install(
$common_instances = hiera_array('common_instances'),
$common_instanceconfig = hiera_array('common_instanceconfigs'),
)
{
define instances (
$common_instanceconfig
) {
common { $common_instances[0]:
name => $title,
path => $common_instanceconfig[0],
version => $common_instanceconfig[1],
files => $common_instanceconfig[2],
pre => $common_instanceconfig[3],
after => $common_instanceconfig[4],
properties => $common_instanceconfig[5],
require => $common_instanceconfig[$title]['require'] ,
}
}
instances {$common_instances:
common_instanceconfig => $common_instanceconfig
}
}
Даже я столкнулся с той же проблемой с вложенными хэшами. Мне пришлось написать код для создания nginx vhosts. Это мой файл YAML
vhost_array:
- host1
- host2
vhost_hash:
host1:
hostname: "one"
docroot: "england"
php_fpm: 2097
db_name: "noidea"
db_passwd: "sheeit"
host2:
hostname: "two"
docroot: "nagaland"
php_fpm: 3000
db_name: "awesm"
db_passwd: "pisss"
И это мой манифест
$vhost_array = hiera_array("vhost_array")
define hash_extract(){
$vhost_hash = hiera_hash("vhost_hash")
$vhost = $vhost_hash[$name] ## TRICK lies in $name variable
notice($vhost['hostname'])
notice($vhost['docroot'])
notice($vhost['php_fpm'])
notice($vhost['db_name'])
notice($vhost['db_passwd'])
}
hash_extract{$vhost_array:}
$ name - это переменная, которая получает значения из массива, и эти значения используются для доступа к хешам. Вы можете дополнительную информацию о переменной $ name можно найти здесь http://docs.puppetlabs.com/puppet/2.7/reference/lang_defined_types.html