Compare commits

...

5 commits

Author SHA1 Message Date
Sloane Hertel
0436f2eeaf
Merge 8af85a0899 into 2c52f969e1 2023-12-07 22:56:39 +00:00
softwarefactory-project-zuul[bot]
2c52f969e1
Merge pull request #484 from flowerysong/firewalld_offline
firewalld: make offline do something

SUMMARY

ansible.posix.firewalld has an offline flag, but it currently does not do anything. What most people expect it to do is allow the task to proceed even when firewalld is offline, so it makes the most sense for it to override the immediate flag and prevent the module from throwing an error in that case.
Fixes #81.
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

firewalld
ADDITIONAL INFORMATION

Reviewed-by: Adam Miller <admiller@redhat.com>
2023-12-07 21:18:29 +00:00
Paul Arthur
695fa213b3 firewalld: make offline do something 2023-11-29 00:06:36 +00:00
s-hertel
8af85a0899 add a changelog 2023-10-31 10:08:34 -04:00
s-hertel
7607c3786f remove deprecated internal argument from synchronize
the new_stdin argument is no longer used to instantiate a connection plugin
2023-10-31 10:08:34 -04:00
5 changed files with 47 additions and 13 deletions

View file

@ -0,0 +1,2 @@
trivial:
- synchronize - instantiate the connection plugin without the ``new_stdin`` argument, which is deprecated in ansible-core 2.15 (https://github.com/ansible-collections/ansible.posix/pull/421).

View file

@ -0,0 +1,2 @@
minor_changes:
- firewalld - added offline flag implementation (https://github.com/ansible-collections/ansible.posix/pull/484)

View file

@ -284,9 +284,6 @@ class ActionModule(ActionBase):
# told (via delegate_to) that a different host is the source of the
# rsync
if not use_delegate and remote_transport:
# Create a connection to localhost to run rsync on
new_stdin = self._connection._new_stdin
# Unlike port, there can be only one shell
localhost_shell = None
for host in C.LOCALHOST:
@ -315,7 +312,11 @@ class ActionModule(ActionBase):
localhost_executable = C.DEFAULT_EXECUTABLE
self._play_context.executable = localhost_executable
new_connection = connection_loader.get('local', self._play_context, new_stdin)
try:
new_connection = connection_loader.get('local', self._play_context)
except TypeError:
# Needed for ansible-core < 2.15
new_connection = connection_loader.get('local', self._play_context, self._connection._new_stdin)
self._connection = new_connection
# Override _remote_is_local as an instance attribute specifically for the synchronize use case
# ensuring we set local tmpdir correctly

View file

@ -84,13 +84,15 @@ options:
type: str
permanent:
description:
- Should this configuration be in the running firewalld configuration or persist across reboots.
- Whether to apply this change to the permanent firewalld configuration.
- As of Ansible 2.3, permanent operations can operate on firewalld configs when it is not running (requires firewalld >= 0.3.9).
- Note that if this is C(false), immediate is assumed C(true).
- Note that if this is C(false), I(immediate) defaults to C(true).
type: bool
default: false
immediate:
description:
- Should this configuration be applied immediately, if set as permanent.
- Whether to apply this change to the runtime firewalld configuration.
- Defaults to C(true) if I(permanent=false).
type: bool
default: false
state:
@ -112,8 +114,9 @@ options:
type: str
offline:
description:
- Whether to run this module even when firewalld is offline.
- Ignores I(immediate) if I(permanent=true) and firewalld is not running.
type: bool
default: false
target:
description:
- firewalld Zone target
@ -142,6 +145,14 @@ author:
'''
EXAMPLES = r'''
- name: permanently enable https service, also enable it immediately if possible
ansible.posix.firewalld:
service: https
state: enabled
permanent: true
immediate: true
offline: true
- name: permit traffic in default zone for https service
ansible.posix.firewalld:
service: https
@ -806,12 +817,12 @@ def main():
zone=dict(type='str'),
immediate=dict(type='bool', default=False),
source=dict(type='str'),
permanent=dict(type='bool'),
permanent=dict(type='bool', default=False),
state=dict(type='str', required=True, choices=['absent', 'disabled', 'enabled', 'present']),
timeout=dict(type='int', default=0),
interface=dict(type='str'),
masquerade=dict(type='str'),
offline=dict(type='bool'),
offline=dict(type='bool', default=False),
target=dict(type='str', choices=['default', 'ACCEPT', 'DROP', '%%REJECT%%']),
),
supports_check_mode=True,
@ -832,19 +843,29 @@ def main():
timeout = module.params['timeout']
interface = module.params['interface']
masquerade = module.params['masquerade']
offline = module.params['offline']
# Sanity checks
FirewallTransaction.sanity_check(module)
# If neither permanent or immediate is provided, assume immediate (as
# written in the module's docs)
# `offline`, `immediate`, and `permanent` have a weird twisty relationship.
if offline:
# specifying offline without permanent makes no sense
if not permanent:
module.fail_json(msg='offline cannot be enabled unless permanent changes are allowed')
# offline overrides immediate to false if firewalld is offline
if fw_offline:
immediate = False
# immediate defaults to true if permanent is not enabled
if not permanent and not immediate:
immediate = True
# Verify required params are provided
if immediate and fw_offline:
module.fail_json(msg='firewall is not currently running, unable to perform immediate actions without a running firewall daemon')
# Verify required params are provided
changed = False
msgs = []
icmp_block = module.params['icmp_block']

View file

@ -21,6 +21,8 @@
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: enabled
register: result
@ -33,6 +35,8 @@
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: enabled
register: result
@ -45,6 +49,8 @@
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: disabled
register: result
@ -57,6 +63,8 @@
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: disabled
register: result