sous-chefs / openvpn

Development repository for the openvpn cookbook
https://supermarket.chef.io/cookbooks/openvpn
Apache License 2.0
98 stars 160 forks source link

setting [:openvpn][:push_options][:"dhcp-option"] - not working #54

Closed danielsand closed 9 years ago

danielsand commented 9 years ago

Hey Folks,

it looks like specifying the push_options attribute doesnt trigger anything

override[:openvpn][:push_options][:"dhcp-option"] = "DNS 10.0.0.2"

when i look into templates/default/server.conf.erb - i dont see any handling inside neither

<% @config.sort.each do |key, value| %>
<% next if value.nil? -%>
<%= key %> <%=
  case value
  when String
    value
  when TrueClass
    1
  when FalseClass
    0
  else
    value
  end
%>
<% end %>

<% unless @push_routes.empty? %>
# additional routes to push to clients
  <% @push_routes.each do |route| %>
push "route <%= route %>"
  <% end %>
<% end %>

same is under providers/conf.rb

i see that variables are passed through node['openvpn']['config'] & node['openvpn']['push_routes'] but nowhere i find node['openvpn']['push_options']

action :create do
  template "/etc/openvpn/#{new_resource.name}.conf" do
    cookbook 'openvpn'
    source "#{new_resource.name}.conf.erb"
    owner 'root'
    group 'root'
    mode 0644
    variables(
      config: new_resource.config || node['openvpn']['config'],
      push_routes: node['openvpn']['push_routes']
    )
  end
end

maybe i'm blind - any hints ?

danielsand commented 9 years ago

found a work around

override[:openvpn][:config][:push] = "\"dhcp-option DNS 10.0.0.2\""
eherot commented 9 years ago

Are you sure you're looking at the right version of the source code? This is what I see in providers/conf.rb:

action :create do
  template "/etc/openvpn/#{new_resource.name}.conf" do
    cookbook new_resource.cookbook
    source "#{new_resource.name}.conf.erb"
    owner 'root'
    group 'root'
    mode 0644
    variables(
      config: new_resource.config || node['openvpn']['config'],
      push_routes: node['openvpn']['push_routes'],
      push_options: node['openvpn']['push_options']
    )
    helpers do
      # rubocop:disable Metrics/MethodLength
      def render_push_options(push_options)
        return [] if push_options.nil?
        push_options.each_with_object([]) do |(option, conf), m|
          case conf
          when Chef::Node::ImmutableArray, Array
            conf.each { |o| m << "push \"#{option} #{o}\"" }
          when String
            m << "push \"#{option} #{conf}\""
          else
            fail "Push option data type #{conf.class} not supported"
          end
        end
      end
      # rubocop:enable Metrics/MethodLength
    end
  end
end

And personally I'd recommend overriding that attribute with entirely strings instead of that sketchy :"string-with-dashes" construct:

override['openvpn']['push_options']['dhcp-option']
danielsand commented 9 years ago

you're right. i'm slightly confused why i have the old version pulled... sorry for the hassle and thanks for the input on the override attribute construct.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.