summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb13
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/linux.rb1
-rw-r--r--lib/chef/resource/ifconfig.rb59
3 files changed, 69 insertions, 4 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb
new file mode 100644
index 0000000000..149b2cb65c
--- /dev/null
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb
@@ -0,0 +1,13 @@
+execute "create virtual interface for testing" do
+ command "ifconfig eth0:0 123.123.22.22"
+end
+
+ifconfig "33.33.33.80" do
+ bootproto "dhcp"
+ device "eth0:0"
+end
+
+ifconfig "Set eth1 to DHCP" do
+ device "eth0:0"
+ bootproto "dhcp"
+end \ No newline at end of file
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
index 0d560b09bd..8991cf1594 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
@@ -123,6 +123,7 @@ include_recipe "::_ohai_hint"
include_recipe "::_openssl"
include_recipe "::_tests"
include_recipe "::_mount"
+include_recipe "::_ifconfig"
# at the moment these do not run properly in docker
# we need to investigate if this is a snap on docker issue or a chef issue
diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb
index ed62ab5952..729658690d 100644
--- a/lib/chef/resource/ifconfig.rb
+++ b/lib/chef/resource/ifconfig.rb
@@ -21,16 +21,67 @@ require_relative "../resource"
class Chef
class Resource
- # @example set a static ip on eth1
- # ifconfig '33.33.33.80' do
- # device 'eth1'
- # end
class Ifconfig < Chef::Resource
unified_mode true
provides :ifconfig
description "Use the **ifconfig** resource to manage interfaces on Unix and Linux systems."
+ examples <<~DOC
+ **Configure a network interface with a static IP**
+
+ ```ruby
+ ifconfig '33.33.33.80' do
+ device 'eth1'
+ end
+ ```
+
+ will create the following interface configuration:
+
+ ```
+ iface eth1 inet static
+ address 33.33.33.80
+ ```
+
+ **Specify a boot protocol**
+
+ ```ruby
+ ifconfig '192.186.0.1' do
+ device 'eth0'
+ end
+ ```
+
+ **Configure an interface to use DHCP**
+
+ ```ruby
+ ifconfig 'Set eth1 to DHCP' do
+ device 'eth1'
+ bootproto 'dhcp'
+ end
+ ```
+
+ will create the following interface configuration:
+
+ ```
+ iface eth1 inet dhcp
+ ```
+
+ **Update a static IP address with a boot protocol**
+
+ ```ruby
+ ifconfig "33.33.33.80" do
+ bootproto "dhcp"
+ device "eth1"
+ end
+ ```
+
+ will update the interface configuration from static to dhcp:
+
+ ```
+ iface eth1 inet dhcp
+ address 33.33.33.80
+ ```
+ DOC
state_attrs :inet_addr, :mask