mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-27 04:50:49 +00:00
module: support a 'ignore_errors' argument
It's more idiomatic for ansible then "on_error". 'ignore_errors' can be specified as a module argument. But it can also be specified on a per-profile level, with the intuitive behavior that the per-profile setting overwrites the per-module setting.
This commit is contained in:
parent
b30bf38957
commit
8682cb64b8
3 changed files with 23 additions and 14 deletions
|
|
@ -460,7 +460,7 @@ class ArgValidator_DictConnection(ArgValidatorDict):
|
|||
ArgValidatorStr ('mac'),
|
||||
ArgValidatorStr ('parent'),
|
||||
ArgValidatorInt ('vlan_id', val_min = 0, val_max = 4095, default_value = None),
|
||||
ArgValidatorStr ('on_error', enum_values = ['continue', 'fail'], default_value = 'fail'),
|
||||
ArgValidatorBool('ignore_errors', default_value = None),
|
||||
ArgValidator_DictIP(),
|
||||
],
|
||||
default_value = dict,
|
||||
|
|
@ -481,9 +481,9 @@ class ArgValidator_DictConnection(ArgValidatorDict):
|
|||
if result['state'] == 'present':
|
||||
VALID_FIELDS.remove('wait')
|
||||
elif result['state'] in ['up', 'down']:
|
||||
VALID_FIELDS = ['name', 'state', 'wait', 'on_error']
|
||||
VALID_FIELDS = ['name', 'state', 'wait', 'ignore_errors']
|
||||
elif result['state'] == 'absent':
|
||||
VALID_FIELDS = ['name', 'state', 'on_error']
|
||||
VALID_FIELDS = ['name', 'state', 'ignore_errors']
|
||||
elif result['state'] == 'wait':
|
||||
VALID_FIELDS = ['state', 'wait']
|
||||
else:
|
||||
|
|
@ -1182,8 +1182,9 @@ class NMUtil:
|
|||
class _AnsibleUtil:
|
||||
|
||||
ARGS = {
|
||||
'provider': { 'required': True, 'default': None, 'type': 'str' },
|
||||
'connections': { 'required': False, 'default': None, 'type': 'list' },
|
||||
'ignore_errors': { 'required': False, 'default': False, 'type': 'str' },
|
||||
'provider': { 'required': True, 'default': None, 'type': 'str' },
|
||||
'connections': { 'required': False, 'default': None, 'type': 'list' },
|
||||
}
|
||||
|
||||
ARGS_CONNECTIONS = ArgValidator_ListConnections()
|
||||
|
|
@ -1283,8 +1284,17 @@ class _AnsibleUtil:
|
|||
|
||||
def log(self, idx, severity, msg, warn_traceback = False):
|
||||
self.run_results[idx]['log'].append((severity, msg))
|
||||
if severity == LogLevel.ERROR and self.connections[idx]['on_error'] != 'continue':
|
||||
self.fail_json('error: %s' % (msg), warn_traceback = warn_traceback)
|
||||
if severity == LogLevel.ERROR:
|
||||
# ignore_errors can be specified per profile. In absense of a
|
||||
# per-profile setting, a global parameter is consulted.
|
||||
ignore_errors = self.connections[idx]['ignore_errors']
|
||||
if ignore_errors is None:
|
||||
try:
|
||||
ignore_errors = Util.boolean(self.params['ignore_errors'])
|
||||
except:
|
||||
ignore_errors = None
|
||||
if not ignore_errors:
|
||||
self.fail_json('error: %s' % (msg), warn_traceback = warn_traceback)
|
||||
|
||||
def _complete_kwargs(self, kwargs, traceback_msg = None):
|
||||
if 'warnings' in kwargs:
|
||||
|
|
|
|||
|
|
@ -130,8 +130,7 @@ class TestValidator(unittest.TestCase):
|
|||
'mac': None,
|
||||
'master': None,
|
||||
'vlan_id': None,
|
||||
'on_error':
|
||||
'fail',
|
||||
'ignore_errors': None,
|
||||
'interface_name': None,
|
||||
'slave_type': None,
|
||||
},
|
||||
|
|
@ -139,7 +138,7 @@ class TestValidator(unittest.TestCase):
|
|||
'name': '5',
|
||||
'state': 'up',
|
||||
'wait': 90,
|
||||
'on_error': 'fail',
|
||||
'ignore_errors': None,
|
||||
}
|
||||
],
|
||||
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
|
||||
|
|
@ -171,8 +170,7 @@ class TestValidator(unittest.TestCase):
|
|||
'mac': None,
|
||||
'master': None,
|
||||
'vlan_id': None,
|
||||
'on_error':
|
||||
'fail',
|
||||
'ignore_errors': None,
|
||||
'interface_name': None,
|
||||
'slave_type': None,
|
||||
'wait': 90,
|
||||
|
|
@ -194,7 +192,7 @@ class TestValidator(unittest.TestCase):
|
|||
{
|
||||
'name': '5',
|
||||
'state': 'absent',
|
||||
'on_error': 'fail',
|
||||
'ignore_errors': None,
|
||||
}
|
||||
],
|
||||
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
|
||||
|
|
@ -230,7 +228,7 @@ class TestValidator(unittest.TestCase):
|
|||
'master': None,
|
||||
'name': '5',
|
||||
'parent': None,
|
||||
'on_error': 'fail',
|
||||
'ignore_errors': None,
|
||||
'slave_type': None,
|
||||
'state': 'present',
|
||||
'type': 'ethernet',
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
- name: Configure networking connection profiles
|
||||
network_connections:
|
||||
provider: "{{ network.provider | default(network_provider) | mandatory }}"
|
||||
ignore_errors: "{{ network.ignore_errors | default(omit) }} "
|
||||
connections: "{{ network.connections | default([]) }}"
|
||||
|
||||
- name: Re-test connectivity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue