From 3a44434a6846baf551cba5ed890d7c9c482dc9fb Mon Sep 17 00:00:00 2001 From: o Date: Sat, 10 Aug 2013 19:08:40 +0200 Subject: avoid collecting duplicate ips in the facts --- lib/facter/strongswan_ips.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/facter/strongswan_ips.rb b/lib/facter/strongswan_ips.rb index 7fac37e..3cb2f69 100644 --- a/lib/facter/strongswan_ips.rb +++ b/lib/facter/strongswan_ips.rb @@ -1,10 +1,12 @@ Facter.add("strongswan_ips") do setcode do - result = nil - if bin = ['/usr/sbin/ipsec', '/usr/sbin/strongswan'].find{|f| File.exists?(f) } - output = Facter::Util::Resolution.exec("#{bin} statusall | grep -E '^ [0-9a-f]'").to_s.split("\n").collect(&:strip) - result = output.join(',') unless output.empty? + bin = ['/usr/sbin/ipsec', '/usr/sbin/strongswan'].find do |f| + File.exists?(f) end - result + return unless bin + output = Facter::Util::Resolution.exec( + "#{bin} statusall | grep -E '^ [0-9a-f]' | sort | uniq") + .to_s.split("\n").collect(&:strip) + output.join(',') unless output.empty? end end -- cgit v1.2.3 From 12b26d899b700be9735903fd457d54f75b0638aa Mon Sep 17 00:00:00 2001 From: o Date: Sat, 10 Aug 2013 19:10:46 +0200 Subject: fix syntax --- lib/facter/strongswan_ips.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/strongswan_ips.rb b/lib/facter/strongswan_ips.rb index 3cb2f69..b1ab7fd 100644 --- a/lib/facter/strongswan_ips.rb +++ b/lib/facter/strongswan_ips.rb @@ -6,7 +6,7 @@ Facter.add("strongswan_ips") do return unless bin output = Facter::Util::Resolution.exec( "#{bin} statusall | grep -E '^ [0-9a-f]' | sort | uniq") - .to_s.split("\n").collect(&:strip) + output = output.to_s.split("\n").collect(&:strip) output.join(',') unless output.empty? end end -- cgit v1.2.3 From 0c7c91c6e3ae96c768f343ff1e5436eb0181989b Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 10 Aug 2013 19:23:58 +0200 Subject: only show installed connections --- manifests/base.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/base.pp b/manifests/base.pp index 1a0b4bf..e4fd1e5 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -37,7 +37,7 @@ class strongswan::base { '/etc/ipsec.conf': content => template('strongswan/ipsec.conf.erb'); "/usr/local/sbin/${binary_name}_connected_hosts": - content => "#!/bin/bash\n${strongswan::binary} status | grep ESTABLISHED | awk -F\\[ '{ print \$1 }'\n", + content => "#!/bin/bash\n${strongswan::binary} status | grep INSTALLED | awk -F\\{ '{ print \$1 }'\n", notify => undef, mode => '0500'; "/usr/local/sbin/${binary_name}_start_unconnected": -- cgit v1.2.3 From 17623a4e889ff61bdf9ac87982ccb09a0bb14f72 Mon Sep 17 00:00:00 2001 From: o Date: Sat, 10 Aug 2013 19:45:07 +0200 Subject: another fix to the factor lib --- lib/facter/strongswan_ips.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/strongswan_ips.rb b/lib/facter/strongswan_ips.rb index b1ab7fd..8875309 100644 --- a/lib/facter/strongswan_ips.rb +++ b/lib/facter/strongswan_ips.rb @@ -3,7 +3,7 @@ Facter.add("strongswan_ips") do bin = ['/usr/sbin/ipsec', '/usr/sbin/strongswan'].find do |f| File.exists?(f) end - return unless bin + break unless bin output = Facter::Util::Resolution.exec( "#{bin} statusall | grep -E '^ [0-9a-f]' | sort | uniq") output = output.to_s.split("\n").collect(&:strip) -- cgit v1.2.3 From f568a45101e8ef78c9bd03f6a8f38b56f1398ded Mon Sep 17 00:00:00 2001 From: o Date: Sat, 10 Aug 2013 19:47:10 +0200 Subject: fix again... --- lib/facter/strongswan_ips.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/facter/strongswan_ips.rb b/lib/facter/strongswan_ips.rb index 8875309..4382d07 100644 --- a/lib/facter/strongswan_ips.rb +++ b/lib/facter/strongswan_ips.rb @@ -3,10 +3,11 @@ Facter.add("strongswan_ips") do bin = ['/usr/sbin/ipsec', '/usr/sbin/strongswan'].find do |f| File.exists?(f) end - break unless bin - output = Facter::Util::Resolution.exec( - "#{bin} statusall | grep -E '^ [0-9a-f]' | sort | uniq") - output = output.to_s.split("\n").collect(&:strip) - output.join(',') unless output.empty? + if bin + output = Facter::Util::Resolution.exec( + "#{bin} statusall | grep -E '^ [0-9a-f]' | sort | uniq") + output = output.to_s.split("\n").collect(&:strip) + output.join(',') unless output.empty? + end end end -- cgit v1.2.3