Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message is missing target and port_forward parameters #255

Closed
strarsis opened this issue Aug 26, 2021 · 1 comment · Fixed by #297
Closed

Error message is missing target and port_forward parameters #255

strarsis opened this issue Aug 26, 2021 · 1 comment · Fixed by #297
Assignees
Labels
bug This issue/PR relates to a bug. has_pr verified This issue has been verified/reproduced by maintainer

Comments

@strarsis
Copy link

SUMMARY

The error message for changing more than one field that can only be exclusively changed at once in a firewalld resource doesn't include the target and port_forward parameters.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.posix.firewalld

ANSIBLE VERSION
ansible 2.9.10
  config file = None
  configured module search path = ['/home/build/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 9.4.0]
COLLECTION VERSION
1.3.0
CONFIGURATION
(empty)
OS / ENVIRONMENT

Ubuntu 20.04 LTS on WSL 2 on Windows 10 x64.

STEPS TO REPRODUCE

Apply an ansible playbook with a firewalld resource changing more than one allowed parameter at once.

(empty)
EXPECTED RESULTS

The warning message should also include the target field.

ACTUAL RESULTS
fatal: [web]: FAILED! => {"changed": false, "msg": "can only operate on port, service, rich_rule, masquerade, icmp_block, icmp_block_inversion, interface or source at once"}
DISCUSSION

modification_count = 0
if icmp_block is not None:
modification_count += 1
if icmp_block_inversion is not None:
modification_count += 1
if service is not None:
modification_count += 1
if port is not None:
modification_count += 1
if port_forward is not None:
modification_count += 1
if rich_rule is not None:
modification_count += 1
if interface is not None:
modification_count += 1
if masquerade is not None:
modification_count += 1
if source is not None:
modification_count += 1
if target is not None:
modification_count += 1
if modification_count > 1:
module.fail_json(
msg='can only operate on port, service, rich_rule, masquerade, icmp_block, icmp_block_inversion, interface or source at once'

Currently a (admittedly easily readable and understandable) if structure is used to determine the number of parameters of a set of parameters that can only be exclusively set per firewalld resource.
The error message is separately constructed, hence it can easily go out of sync with that counting code above.
An alternative could be defining a set of these only exclusively settable fields and count these and generate the error message by using that set as a single source of truth.

@saito-hideki saito-hideki added feature This issue/PR relates to a feature request. verified This issue has been verified/reproduced by maintainer waiting_on_contributor Needs help. Feel free to engage to get things unblocked labels Aug 27, 2021
@saito-hideki
Copy link
Collaborator

I think your opinion is reasonable. It would be better including the targets in the error message. Thank you for reporting this! :)

@saito-hideki saito-hideki added has_pr bug This issue/PR relates to a bug. and removed waiting_on_contributor Needs help. Feel free to engage to get things unblocked feature This issue/PR relates to a feature request. labels Nov 29, 2021
@saito-hideki saito-hideki self-assigned this Nov 29, 2021
ansible-zuul bot added a commit that referenced this issue Nov 29, 2021
Refine the handling of exclusive options

SUMMARY
Refine the handling of exclusive options using mutually_exclusive:

Fixes #255

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ansible.posix.firewalld

ADDITIONAL INFORMATION
None

Reviewed-by: Adam Miller <maxamillion@fedoraproject.org>
Reviewed-by: None <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug. has_pr verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants