diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9f598a4e..b667d235 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -41,23 +41,23 @@ Lint/Void: # Offense count: 10 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 83 + Max: 85 # Offense count: 11 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: - Max: 199 + Max: 256 # Offense count: 4 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: - Max: 30 + Max: 32 # Offense count: 13 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 44 + Max: 50 # Offense count: 1 # Configuration parameters: Max, CountKeywordArgs. @@ -67,7 +67,7 @@ Metrics/ParameterLists: # Offense count: 4 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 33 + Max: 35 # Offense count: 3 Naming/AccessorMethodName: diff --git a/README.md b/README.md index 7622da5c..03f498a8 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ resources out yourself. * stripesize (Parameter) - The stripesize to use for the new logical volume. * thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool or to pool name to create thin volume * volume_group (Parameter) - The volume group name associated with this logical volume. This will automatically set this volume group as a dependency, but it must be defined elsewhere using the volume_group resource type. +* yes_flag (Parameter) - Default value: `false` - If set to true, do not prompt for confirmation interactively but always assume the answer yes. ### physical_volume diff --git a/lib/puppet/provider/logical_volume/lvm.rb b/lib/puppet/provider/logical_volume/lvm.rb index 60db74bf..aa19d5e1 100644 --- a/lib/puppet/provider/logical_volume/lvm.rb +++ b/lib/puppet/provider/logical_volume/lvm.rb @@ -118,6 +118,8 @@ def create else args << @resource[:volume_group] end + + args.push('--yes') if @resource[:yes_flag] lvcreate(*args) end @@ -183,7 +185,10 @@ def size=(new_size) end if resizeable - lvextend('-L', new_size, path) || raise("Cannot extend to size #{new_size} because lvextend failed.") + args = [] + args.push('--yes') if @resource[:yes_flag] + + lvextend('-L', new_size, path, *args) || raise("Cannot extend to size #{new_size} because lvextend failed.") unless @resource[:resize_fs] == :false || @resource[:resize_fs] == false || @resource[:resize_fs] == 'false' begin diff --git a/lib/puppet/type/logical_volume.rb b/lib/puppet/type/logical_volume.rb index 22300008..c1e5ed2b 100644 --- a/lib/puppet/type/logical_volume.rb +++ b/lib/puppet/type/logical_volume.rb @@ -180,6 +180,11 @@ def insync?(is) end end + newparam(:yes_flag) do + desc 'If set to true, do not prompt for confirmation interactively but always assume the answer yes.' + defaultto false + end + autorequire(:volume_group) do @parameters[:volume_group].value end diff --git a/manifests/logical_volume.pp b/manifests/logical_volume.pp index 0fe3fb05..362f31f9 100644 --- a/manifests/logical_volume.pp +++ b/manifests/logical_volume.pp @@ -49,6 +49,8 @@ # :inherit # :normal +# @param yes_flag If set to true, do not prompt for confirmation interactively but always assume the answer yes. + # define lvm::logical_volume ( String[1] $volume_group, @@ -78,6 +80,7 @@ Optional[Boolean] $no_sync = undef, Optional[Variant[String[1], Integer]] $region_size = undef, Optional[Enum['anywhere', 'contiguous', 'cling', 'inherit', 'normal']] $alloc = undef, + Boolean $yes_flag = false, ) { $lvm_device_path = "/dev/${volume_group}/${name}" @@ -139,6 +142,7 @@ no_sync => $no_sync, region_size => $region_size, alloc => $alloc, + yes_flag => $yes_flag, } if $createfs { diff --git a/tasks/ensure_lv.json b/tasks/ensure_lv.json index 9510fde2..d859f8cb 100644 --- a/tasks/ensure_lv.json +++ b/tasks/ensure_lv.json @@ -80,6 +80,10 @@ "region_size": { "description": "A mirror is divided into regions of this size (in MB), the mirror log uses this granularity to track which regions are in sync. CAN NOT BE CHANGED on already mirrored volume. Take your mirror size in terabytes and round up that number to the next power of 2, using that number as the -R argument.", "type": "Optional[Integer]" - } + }, + "yes_flag": { + "description": "If set to true, do not prompt for confirmation interactively but always assume the answer yes.", + "type": "Boolean" + } } -} \ No newline at end of file +} diff --git a/tasks/ensure_lv.rb b/tasks/ensure_lv.rb index aa5c97b0..5690e4c4 100755 --- a/tasks/ensure_lv.rb +++ b/tasks/ensure_lv.rb @@ -50,6 +50,7 @@ logical_volume[:alloc] = params['alloc'] if params['alloc'] logical_volume[:no_sync] = params['no_sync'] if params['no_sync'] logical_volume[:region_size] = params['region_size'] if params['region_size'] +logical_volume[:yes_flag] = params['yes_flag'] if params['yes_flag'] # Save the result _resource, report = Puppet::Resource.indirection.save(logical_volume)