Allows iptables chain creation with wait parameter (#84491)

* Allows iptables chain creation with wait parameter

Fixes #84490

* Add the changelog fragment for 84490
pull/84554/head
Kristopher Newsome 11 months ago committed by GitHub
parent 8588401387
commit f727d74fc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- iptables - Allows the wait paramater to be used with iptables chain creation (https://github.com/ansible/ansible/issues/84490)

@ -614,7 +614,6 @@ def append_wait(rule, param, flag):
def construct_rule(params): def construct_rule(params):
rule = [] rule = []
append_wait(rule, params['wait'], '-w')
append_param(rule, params['protocol'], '-p', False) append_param(rule, params['protocol'], '-p', False)
append_param(rule, params['source'], '-s', False) append_param(rule, params['source'], '-s', False)
append_param(rule, params['destination'], '-d', False) append_param(rule, params['destination'], '-d', False)
@ -701,6 +700,8 @@ def push_arguments(iptables_path, action, params, make_rule=True):
cmd.extend([action, params['chain']]) cmd.extend([action, params['chain']])
if action == '-I' and params['rule_num']: if action == '-I' and params['rule_num']:
cmd.extend([params['rule_num']]) cmd.extend([params['rule_num']])
if params['wait']:
cmd.extend(['-w', params['wait']])
if make_rule: if make_rule:
cmd.extend(construct_rule(params)) cmd.extend(construct_rule(params))
return cmd return cmd
@ -861,6 +862,7 @@ def main():
rule=' '.join(construct_rule(module.params)), rule=' '.join(construct_rule(module.params)),
state=module.params['state'], state=module.params['state'],
chain_management=module.params['chain_management'], chain_management=module.params['chain_management'],
wait=module.params['wait'],
) )
ip_version = module.params['ip_version'] ip_version = module.params['ip_version']
@ -910,7 +912,7 @@ def main():
else: else:
# Create the chain if there are no rule arguments # Create the chain if there are no rule arguments
if (args['state'] == 'present') and not args['rule']: if (args['state'] == 'present') and not args['rule'] and args['chain_management']:
chain_is_present = check_chain_present( chain_is_present = check_chain_present(
iptables_path, module, module.params iptables_path, module, module.params
) )

@ -1196,6 +1196,7 @@ def test_chain_creation(mocker):
"chain": "FOOBAR", "chain": "FOOBAR",
"state": "present", "state": "present",
"chain_management": True, "chain_management": True,
"wait": 10,
} }
) )
@ -1224,6 +1225,8 @@ def test_chain_creation(mocker):
"filter", "filter",
"-L", "-L",
"FOOBAR", "FOOBAR",
"-w",
"10",
] ]
second_cmd_args_list = run_command.call_args_list[1] second_cmd_args_list = run_command.call_args_list[1]
@ -1233,6 +1236,8 @@ def test_chain_creation(mocker):
"filter", "filter",
"-N", "-N",
"FOOBAR", "FOOBAR",
"-w",
"10",
] ]
commands_results = [ commands_results = [
@ -1257,6 +1262,7 @@ def test_chain_creation_check_mode(mocker):
"chain": "FOOBAR", "chain": "FOOBAR",
"state": "present", "state": "present",
"chain_management": True, "chain_management": True,
"wait": 10,
"_ansible_check_mode": True, "_ansible_check_mode": True,
} }
) )
@ -1285,6 +1291,8 @@ def test_chain_creation_check_mode(mocker):
"filter", "filter",
"-L", "-L",
"FOOBAR", "FOOBAR",
"-w",
"10",
] ]
commands_results = [ commands_results = [

Loading…
Cancel
Save