Puppet : 利用方法 [exec リソース]2023/10/17 |
|
マニフェストで宣言できるリソースタイプのうち、[exec] リソースを例にします。 [exec] リソースでは任意のコマンドを実行できますが、それゆえに危険であり、[exec] を使うのは他のイベントを検知した際にのみ特定のコマンドを実行する、といった使い方に留めておくことが Puppet 公式で推奨されています。 |
|
| [1] | [/home/test2.txt] が変更された場合のみ、[echo "copy test2.txt" | tee /home/copy-test2.txt] コマンドを実行する。 [refreshonly] で [true] を指定し、[subscribe] で指定したリソースを監視することで例のような動作を実現できる。 |
|
[root@dlp ~]#
vi /etc/puppetlabs/code/environments/production/manifests/cmd01.pp
file { '/home/test2.txt':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet://dlp.srv.world/extra_files/test2.txt'
}
exec { 'echo "copy test2.txt" | tee /home/copy-test2.txt':
path => ['/usr/bin', '/usr/sbin'],
subscribe => File['/home/test2.txt'],
refreshonly => true
}
|
| Sponsored Link |
|
|