スクリプトの先頭に「ファイルが見つからない場合は実行します」というルビ
概要
重複コードを減らそうとしている Ruby ファイルがいくつかあります。以下は、反復的なコードが多数含まれている、より大きなファイルのスニペットです。 if node[‘platform_version’] =~ /10.0.14393/ セクションに not_if { ::File.exist?(‘C:/programdata/haveat/chef-base/files/missing_GPO_entries_from_patching.flg’ を追加することはできますか? ) } レジストリ変更ごとに個別にリストする必要がないようにするには? if node = this かつ flg ファイルが見つからない場合のようなもの
# If OS is 2016
if node['platform_version'] =~ /10.0.14393/
registry_key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection' do
values [
{ name: 'AllowTelemetry', type: :dword, data: 0x00000000 },
]
action :create_if_missing
not_if { ::File.exist?('C:/programdata/habitat/chef-base/files/missing_GPO_entries_from_patching.flg') }
end
end
解決策
こういう意味ですか?
if node['platform_version'] =~ /10.0.14393/ && !File.exist?('C:/programdata/habitat/chef-base/files/missing_GPO_entries_from_patching.flg')
# ...
end