ローカル システム上のファイルを使用して、Chef を使用して UFW ファイアウォール ルールを設定したいと考えています。firewall
レシピ ( https://supermarket.chef.io/cookbooks/firewall ) にはこれを行う機能がありますが、ブロックに変数を渡そうとするとエラーが発生します。
IP アドレス/サブネットをハードコーディングすると、すべて正常に動作します。まったく同じ IP/サブネットをファイルに入れると、無効な IP アドレス エラーが発生します。
以下のコードでは、最初のfirewall_rule
ブロックは実行されますが、2 番目以降のブロックは実行され"#{subnet}"
ません。また、同じ結果の文字列置換を使用する代わりに、変数を直接渡すことも試みました。
# Try to read from the client list of IPs
if File.exist?("/secure/targs/client.lst") then
File.open("/secure/targs/client.lst", "r") do |subnets|
subnets.each_line do |subnet|
# Only allow outbound connection to in-scope targs
firewall_rule 'client-out-ether' do
interface 'eno1'
destination "10.0.0.128/25"
direction :out
command :allow
end
firewall_rule 'client-out-wifi' do
interface 'wlp58s0'
destination "#{subnet}"
direction :out
command :allow
end
# Allow inbound connections from in-scope targs
# Ideally we scope this to specific ports
# OR remove this and do it manually as needed
firewall_rule 'client-in-eth' do
dest_interface 'eno0'
source "#{subnet}"
command :allow
end
firewall_rule 'client-in-wifi' do
dest_interface 'wlp58s0'
source "#{subnet}"
command :allow
end
end
end
# Default allow all out on client interfaces if scope not defined
else
firewall_rule 'client-out-ether' do
interface 'eno1'
direction :out
command :allow
end
firewall_rule 'client-out-wifi' do
interface 'wlp58s0'
direction :out
command :allow
end
end
これは構文の問題だと推測していますが、これは通常の Ruby 構文で動作するはずです。レシピが提供された変数をリテラルとして読み取っているようです。