diff options
author | Tim Smith <tsmith@chef.io> | 2020-10-08 15:35:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 15:35:54 -0700 |
commit | 453d2436d360f7a95b05aa467dc749f1b9cc1bb3 (patch) | |
tree | 6a851190a7de2051f6f44a4288d665f631f3dd4a | |
parent | be456a25598166c437182283c224e93b81017277 (diff) | |
parent | fd1ed1bd6aa44c1b18586b3fbaf69b4deb968028 (diff) | |
download | chef-453d2436d360f7a95b05aa467dc749f1b9cc1bb3.tar.gz |
Merge pull request #10489 from jmherbst/ifconfig-10457
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/provider/ifconfig.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/ifconfig/debian.rb | 48 | ||||
-rw-r--r-- | lib/chef/provider/ifconfig/redhat.rb | 68 |
3 files changed, 85 insertions, 33 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb index d5e18ae730..9ae2c38137 100644 --- a/lib/chef/provider/ifconfig.rb +++ b/lib/chef/provider/ifconfig.rb @@ -236,7 +236,7 @@ class Chef return unless can_generate_config? b = binding - template = ::ERB.new(@config_template) + template = ::ERB.new(@config_template, nil, "-") config = resource_for_config(@config_path) config.content(template.result(b)) config.run_action(:create) diff --git a/lib/chef/provider/ifconfig/debian.rb b/lib/chef/provider/ifconfig/debian.rb index 17d5fdd243..7406ad0228 100644 --- a/lib/chef/provider/ifconfig/debian.rb +++ b/lib/chef/provider/ifconfig/debian.rb @@ -32,25 +32,43 @@ class Chef def initialize(new_resource, run_context) super(new_resource, run_context) @config_template = %{ -<% if new_resource.device %> -<% if new_resource.onboot == "yes" %>auto <%= new_resource.device %><% end %> +<% if new_resource.device -%> +<% if new_resource.onboot == "yes" -%> +auto <%= new_resource.device %> +<% end -%> <% case new_resource.bootproto - when "dhcp" %> + when "dhcp" -%> iface <%= new_resource.device %> <%= new_resource.family %> dhcp -<% when "bootp" %> +<% when "bootp" -%> iface <%= new_resource.device %> <%= new_resource.family %> bootp -<% else %> +<% else -%> iface <%= new_resource.device %> <%= new_resource.family %> static - <% if new_resource.target %>address <%= new_resource.target %><% end %> - <% if new_resource.mask %>netmask <%= new_resource.mask %><% end %> - <% if new_resource.network %>network <%= new_resource.network %><% end %> - <% if new_resource.bcast %>broadcast <%= new_resource.bcast %><% end %> - <% if new_resource.metric %>metric <%= new_resource.metric %><% end %> - <% if new_resource.hwaddr %>hwaddress <%= new_resource.hwaddr %><% end %> - <% if new_resource.mtu %>mtu <%= new_resource.mtu %><% end %> - <% if new_resource.gateway %>gateway <%= new_resource.gateway %><% end %> -<% end %> -<% end %> + <% if new_resource.target -%> + address <%= new_resource.target %> + <% end -%> + <% if new_resource.mask -%> + netmask <%= new_resource.mask %> + <% end -%> + <% if new_resource.network -%> + network <%= new_resource.network %> + <% end -%> + <% if new_resource.bcast -%> + broadcast <%= new_resource.bcast %> + <% end -%> + <% if new_resource.metric -%> + metric <%= new_resource.metric %> + <% end -%> + <% if new_resource.hwaddr -%> + hwaddress <%= new_resource.hwaddr %> + <% end -%> + <% if new_resource.mtu -%> + mtu <%= new_resource.mtu %> + <% end -%> + <% if new_resource.gateway -%> + gateway <%= new_resource.gateway %> + <% end -%> +<% end -%> +<% end -%> } @config_path = "#{INTERFACES_DOT_D_DIR}/ifcfg-#{new_resource.device}" end diff --git a/lib/chef/provider/ifconfig/redhat.rb b/lib/chef/provider/ifconfig/redhat.rb index 44cfe31ea7..2fbb9ff958 100644 --- a/lib/chef/provider/ifconfig/redhat.rb +++ b/lib/chef/provider/ifconfig/redhat.rb @@ -27,23 +27,57 @@ class Chef def initialize(new_resource, run_context) super(new_resource, run_context) @config_template = %{ -<% if new_resource.device %>DEVICE=<%= new_resource.device %><% end %> -<% if new_resource.onboot == "yes" %>ONBOOT=<%= new_resource.onboot %><% end %> -<% if new_resource.bootproto %>BOOTPROTO=<%= new_resource.bootproto %><% end %> -<% if new_resource.target %>IPADDR=<%= new_resource.target %><% end %> -<% if new_resource.mask %>NETMASK=<%= new_resource.mask %><% end %> -<% if new_resource.network %>NETWORK=<%= new_resource.network %><% end %> -<% if new_resource.bcast %>BROADCAST=<%= new_resource.bcast %><% end %> -<% if new_resource.onparent %>ONPARENT=<%= new_resource.onparent %><% end %> -<% if new_resource.hwaddr %>HWADDR=<%= new_resource.hwaddr %><% end %> -<% if new_resource.metric %>METRIC=<%= new_resource.metric %><% end %> -<% if new_resource.mtu %>MTU=<%= new_resource.mtu %><% end %> -<% if new_resource.ethtool_opts %>ETHTOOL_OPTS="<%= new_resource.ethtool_opts %>"<% end %> -<% if new_resource.bonding_opts %>BONDING_OPTS="<%= new_resource.bonding_opts %>"<% end %> -<% if new_resource.master %>MASTER=<%= new_resource.master %><% end %> -<% if new_resource.slave %>SLAVE=<%= new_resource.slave %><% end %> -<% if new_resource.vlan %>VLAN=<%= new_resource.vlan %><% end %> -<% if new_resource.gateway %>GATEWAY=<%= new_resource.gateway %><% end %> +<% if new_resource.device -%> +DEVICE=<%= new_resource.device %> +<% end -%> +<% if new_resource.onboot == "yes" -%> +ONBOOT=<%= new_resource.onboot %> +<% end -%> +<% if new_resource.bootproto -%> +BOOTPROTO=<%= new_resource.bootproto %> +<% end -%> +<% if new_resource.target -%> +IPADDR=<%= new_resource.target %> +<% end -%> +<% if new_resource.mask -%> +NETMASK=<%= new_resource.mask %> +<% end -%> +<% if new_resource.network -%> +NETWORK=<%= new_resource.network %> +<% end -%> +<% if new_resource.bcast -%> +BROADCAST=<%= new_resource.bcast %> +<% end -%> +<% if new_resource.onparent -%> +ONPARENT=<%= new_resource.onparent %> +<% end -%> +<% if new_resource.hwaddr -%> +HWADDR=<%= new_resource.hwaddr %> +<% end -%> +<% if new_resource.metric -%> +METRIC=<%= new_resource.metric %> +<% end -%> +<% if new_resource.mtu -%> +MTU=<%= new_resource.mtu %> +<% end -%> +<% if new_resource.ethtool_opts -%> +ETHTOOL_OPTS="<%= new_resource.ethtool_opts %>" +<% end -%> +<% if new_resource.bonding_opts -%> +BONDING_OPTS="<%= new_resource.bonding_opts %>" +<% end -%> +<% if new_resource.master -%> +MASTER=<%= new_resource.master %> +<% end -%> +<% if new_resource.slave -%> +SLAVE=<%= new_resource.slave %> +<% end -%> +<% if new_resource.vlan -%> +VLAN=<%= new_resource.vlan %> +<% end -%> +<% if new_resource.gateway -%> +GATEWAY=<%= new_resource.gateway %> +<% end -%> } @config_path = "/etc/sysconfig/network-scripts/ifcfg-#{new_resource.device}" end |