Puppet Boltはタスク実行ツールです。 Puppetのタスクやマニフェストを実行することができます。この記事はこちらの原文を元に作成しています。
環境
- Puppet BoltとPuppet Development Kitのインストール先OS : macOS Mojave 10.14.2
- nginxのインストール先OS : ubuntu 4.15.0-1027
- Puppet Boltのバージョン : 1.11.0
- Puppet Development Kitのバージョン : 1.9.0
手順
Boltをインストールします。
$ brew cask install puppetlabs/puppet/puppet-bolt
PDKをインストールします。
$ brew cask install puppetlabs/puppet/pdk
Puppetのモジュールを新規に作成します。質問には全てデフォルトで答えて最後にyesと答えます。
$ cd ~/.puppetlabs/etc/code/modules
$ pdk new module profiles
省略
Metadata will be generated based on this information, continue? Yes
pdk (INFO): Module 'profiles' generated at path '/Users/hisashi_yamaguchi/.puppetlabs/etc/code/modules/profiles', from template 'file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git'.
pdk (INFO): In your module directory, add classes with the 'pdk new class' command.
作成したモジュールディレクトリの直下にplansディレクトリを作成します。
$ mkdir ~/.puppetlabs/etc/code/modules/profiles/plans
plansディレクトリにPuppetのマニフェストを作成します。
$ vi ~/.puppetlabs/etc/code/modules/profiles/plans/nginx_install.pp
plan profiles::nginx_install(
TargetSpec $nodes,
String $site_content = 'hello!',
) {
# Install puppet on the target and gather facts
$nodes.apply_prep
# Compile the manifest block into a catalog
apply($nodes) {
package { 'nginx':
ensure => present,
}
file { '/var/www/html/index.html':
content => $site_content,
ensure => file,
}
service { 'nginx':
ensure => 'running',
enable => 'true',
require => Package['nginx'],
}
}
}
Boltでマニフェストを実行します。-nでホスト名を、-uでsshのログインユーザを指定します。
$ bolt plan run profiles::nginx_install -n ubuntu --modulepath ~/.puppetlabs/etc/code/modules/ -u hisashi_yamaguchi --run-as root
Starting: plan profiles::nginx_install
Starting: install puppet and gather facts on ubuntu
Finished: install puppet and gather facts with 0 failures in 73.96 sec
Starting: apply catalog on ubuntu
Finished: apply catalog with 0 failures in 26.5 sec
Finished: plan profiles::nginx_install in 100.48 sec
Plan completed successfully with no result
Chromeでhttp://<ホスト名>にアクセスします。hello!が表示されれば成功です。