mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-03-10 03:25:22 +01:00
Compare commits
1 commit
7812b99590
...
6c41ed1bfd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c41ed1bfd |
7 changed files with 33 additions and 75 deletions
|
|
@ -1,4 +0,0 @@
|
||||||
---
|
|
||||||
trivial:
|
|
||||||
- mount - fix description in the documentation of the state ``absent`` to match its actual behavior
|
|
||||||
and point out that ``src`` is ignored with state ``absent`` and ``unmounted`` (https://github.com/ansible-collections/ansible.posix/issues/322)
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
---
|
|
||||||
bugfixes:
|
|
||||||
- seboolean - make it work with disabled SELinux
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- "Add summary_only parameter to profile_roles and profile_tasks callbacks."
|
|
||||||
|
|
@ -14,19 +14,6 @@ DOCUMENTATION = '''
|
||||||
- This callback module provides profiling for ansible roles.
|
- This callback module provides profiling for ansible roles.
|
||||||
requirements:
|
requirements:
|
||||||
- whitelisting in configuration
|
- whitelisting in configuration
|
||||||
options:
|
|
||||||
summary_only:
|
|
||||||
description:
|
|
||||||
- Only show summary, not individual task profiles.
|
|
||||||
Especially usefull in combination with C(DISPLAY_SKIPPED_HOSTS=false) and/or C(ANSIBLE_DISPLAY_OK_HOSTS=false).
|
|
||||||
type: bool
|
|
||||||
default: False
|
|
||||||
env:
|
|
||||||
- name: PROFILE_ROLES_SUMMARY_ONLY
|
|
||||||
ini:
|
|
||||||
- section: callback_profile_roles
|
|
||||||
key: summary_only
|
|
||||||
version_added: 1.5.0
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
@ -89,26 +76,13 @@ class CallbackModule(CallbackBase):
|
||||||
self.stats = collections.Counter()
|
self.stats = collections.Counter()
|
||||||
self.totals = collections.Counter()
|
self.totals = collections.Counter()
|
||||||
self.current = None
|
self.current = None
|
||||||
|
|
||||||
self.summary_only = None
|
|
||||||
|
|
||||||
super(CallbackModule, self).__init__()
|
super(CallbackModule, self).__init__()
|
||||||
|
|
||||||
def set_options(self, task_keys=None, var_options=None, direct=None):
|
|
||||||
|
|
||||||
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
|
||||||
|
|
||||||
self.summary_only = self.get_option('summary_only')
|
|
||||||
|
|
||||||
def _display_tasktime(self):
|
|
||||||
if not self.summary_only:
|
|
||||||
self._display.display(tasktime())
|
|
||||||
|
|
||||||
def _record_task(self, task):
|
def _record_task(self, task):
|
||||||
"""
|
"""
|
||||||
Logs the start of each task
|
Logs the start of each task
|
||||||
"""
|
"""
|
||||||
self._display_tasktime()
|
self._display.display(tasktime())
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
||||||
if task._role:
|
if task._role:
|
||||||
|
|
@ -125,10 +99,10 @@ class CallbackModule(CallbackBase):
|
||||||
self._record_task(task)
|
self._record_task(task)
|
||||||
|
|
||||||
def playbook_on_setup(self):
|
def playbook_on_setup(self):
|
||||||
self._display_tasktime()
|
self._display.display(tasktime())
|
||||||
|
|
||||||
def playbook_on_stats(self, stats):
|
def playbook_on_stats(self, stats):
|
||||||
self._display_tasktime()
|
self._display.display(tasktime())
|
||||||
self._display.display(filled("", fchar="="))
|
self._display.display(filled("", fchar="="))
|
||||||
|
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
|
||||||
|
|
@ -40,18 +40,6 @@ DOCUMENTATION = '''
|
||||||
ini:
|
ini:
|
||||||
- section: callback_profile_tasks
|
- section: callback_profile_tasks
|
||||||
key: sort_order
|
key: sort_order
|
||||||
summary_only:
|
|
||||||
description:
|
|
||||||
- Only show summary, not individual task profiles.
|
|
||||||
Especially usefull in combination with C(DISPLAY_SKIPPED_HOSTS=false) and/or C(ANSIBLE_DISPLAY_OK_HOSTS=false).
|
|
||||||
type: bool
|
|
||||||
default: False
|
|
||||||
env:
|
|
||||||
- name: PROFILE_TASKS_SUMMARY_ONLY
|
|
||||||
ini:
|
|
||||||
- section: callback_profile_tasks
|
|
||||||
key: summary_only
|
|
||||||
version_added: 1.5.0
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
|
@ -132,7 +120,6 @@ class CallbackModule(CallbackBase):
|
||||||
self.current = None
|
self.current = None
|
||||||
|
|
||||||
self.sort_order = None
|
self.sort_order = None
|
||||||
self.summary_only = None
|
|
||||||
self.task_output_limit = None
|
self.task_output_limit = None
|
||||||
|
|
||||||
super(CallbackModule, self).__init__()
|
super(CallbackModule, self).__init__()
|
||||||
|
|
@ -150,8 +137,6 @@ class CallbackModule(CallbackBase):
|
||||||
elif self.sort_order == 'none':
|
elif self.sort_order == 'none':
|
||||||
self.sort_order = None
|
self.sort_order = None
|
||||||
|
|
||||||
self.summary_only = self.get_option('summary_only')
|
|
||||||
|
|
||||||
self.task_output_limit = self.get_option('output_limit')
|
self.task_output_limit = self.get_option('output_limit')
|
||||||
if self.task_output_limit is not None:
|
if self.task_output_limit is not None:
|
||||||
if self.task_output_limit == 'all':
|
if self.task_output_limit == 'all':
|
||||||
|
|
@ -159,15 +144,11 @@ class CallbackModule(CallbackBase):
|
||||||
else:
|
else:
|
||||||
self.task_output_limit = int(self.task_output_limit)
|
self.task_output_limit = int(self.task_output_limit)
|
||||||
|
|
||||||
def _display_tasktime(self):
|
|
||||||
if not self.summary_only:
|
|
||||||
self._display.display(tasktime())
|
|
||||||
|
|
||||||
def _record_task(self, task):
|
def _record_task(self, task):
|
||||||
"""
|
"""
|
||||||
Logs the start of each task
|
Logs the start of each task
|
||||||
"""
|
"""
|
||||||
self._display_tasktime()
|
self._display.display(tasktime())
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
||||||
# Record the start time of the current task
|
# Record the start time of the current task
|
||||||
|
|
@ -190,10 +171,10 @@ class CallbackModule(CallbackBase):
|
||||||
self._record_task(task)
|
self._record_task(task)
|
||||||
|
|
||||||
def playbook_on_setup(self):
|
def playbook_on_setup(self):
|
||||||
self._display_tasktime()
|
self._display.display(tasktime())
|
||||||
|
|
||||||
def playbook_on_stats(self, stats):
|
def playbook_on_stats(self, stats):
|
||||||
self._display_tasktime()
|
self._display.display(tasktime())
|
||||||
self._display.display(filled("", fchar="="))
|
self._display.display(filled("", fchar="="))
|
||||||
|
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ options:
|
||||||
description:
|
description:
|
||||||
- Device (or NFS volume, or something else) to be mounted on I(path).
|
- Device (or NFS volume, or something else) to be mounted on I(path).
|
||||||
- Required when I(state) set to C(present), C(mounted) or C(ephemeral).
|
- Required when I(state) set to C(present), C(mounted) or C(ephemeral).
|
||||||
- Ignored when I(state) set to C(absent) or C(unmounted).
|
|
||||||
type: path
|
type: path
|
||||||
fstype:
|
fstype:
|
||||||
description:
|
description:
|
||||||
|
|
@ -76,13 +75,9 @@ options:
|
||||||
the module will fail to avoid unexpected unmount or mount point override.
|
the module will fail to avoid unexpected unmount or mount point override.
|
||||||
If the mount point is not present, the mount point will be created.
|
If the mount point is not present, the mount point will be created.
|
||||||
The I(fstab) is completely ignored. This option is added in version 1.5.0.
|
The I(fstab) is completely ignored. This option is added in version 1.5.0.
|
||||||
- C(absent) specifies that the mount point entry I(path) will be removed
|
- C(absent) specifies that the device mount's entry will be removed from
|
||||||
from I(fstab) and will also unmount the mounted device and remove the
|
I(fstab) and will also unmount the device and remove the mount
|
||||||
mount point. A mounted device will be unmounted regardless of I(src) or its
|
point.
|
||||||
real source. C(absent) does not unmount recursively, and the module will
|
|
||||||
fail if multiple devices are mounted on the same mount point. Using
|
|
||||||
C(absent) with a mount point that is not registered in the I(fstab) has
|
|
||||||
no effect. Use C(unmounted) instead..
|
|
||||||
- C(remounted) specifies that the device will be remounted for when you
|
- C(remounted) specifies that the device will be remounted for when you
|
||||||
want to force a refresh on the mount itself (added in 2.9). This will
|
want to force a refresh on the mount itself (added in 2.9). This will
|
||||||
always return changed=true. If I(opts) is set, the options will be
|
always return changed=true. If I(opts) is set, the options will be
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,8 @@ except ImportError:
|
||||||
HAVE_SEMANAGE = False
|
HAVE_SEMANAGE = False
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils.six import binary_type
|
||||||
|
from ansible.module_utils._text import to_bytes, to_text
|
||||||
from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL
|
from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,6 +82,23 @@ def get_runtime_status(ignore_selinux_state=False):
|
||||||
return True if ignore_selinux_state is True else selinux.is_selinux_enabled()
|
return True if ignore_selinux_state is True else selinux.is_selinux_enabled()
|
||||||
|
|
||||||
|
|
||||||
|
def has_boolean_value(module, name):
|
||||||
|
bools = []
|
||||||
|
try:
|
||||||
|
rc, bools = selinux.security_get_boolean_names()
|
||||||
|
except OSError:
|
||||||
|
module.fail_json(msg="Failed to get list of boolean names")
|
||||||
|
# work around for selinux who changed its API, see
|
||||||
|
# https://github.com/ansible/ansible/issues/25651
|
||||||
|
if len(bools) > 0:
|
||||||
|
if isinstance(bools[0], binary_type):
|
||||||
|
name = to_bytes(name)
|
||||||
|
if name in bools:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_boolean_value(module, name):
|
def get_boolean_value(module, name):
|
||||||
state = 0
|
state = 0
|
||||||
try:
|
try:
|
||||||
|
|
@ -156,10 +174,7 @@ def semanage_set_boolean_value(module, handle, name, value):
|
||||||
semanage.semanage_handle_destroy(handle)
|
semanage.semanage_handle_destroy(handle)
|
||||||
module.fail_json(msg="Failed to modify boolean key with semanage")
|
module.fail_json(msg="Failed to modify boolean key with semanage")
|
||||||
|
|
||||||
if (
|
if semanage.semanage_bool_set_active(handle, boolkey, sebool) < 0:
|
||||||
selinux.is_selinux_enabled()
|
|
||||||
and semanage.semanage_bool_set_active(handle, boolkey, sebool) < 0
|
|
||||||
):
|
|
||||||
semanage.semanage_handle_destroy(handle)
|
semanage.semanage_handle_destroy(handle)
|
||||||
module.fail_json(msg="Failed to set boolean key active with semanage")
|
module.fail_json(msg="Failed to set boolean key active with semanage")
|
||||||
|
|
||||||
|
|
@ -300,9 +315,12 @@ def main():
|
||||||
# Feature only available in selinux library since 2012.
|
# Feature only available in selinux library since 2012.
|
||||||
name = selinux.selinux_boolean_sub(name)
|
name = selinux.selinux_boolean_sub(name)
|
||||||
|
|
||||||
|
if not has_boolean_value(module, name):
|
||||||
|
module.fail_json(msg="SELinux boolean %s does not exist." % name)
|
||||||
|
|
||||||
if persistent:
|
if persistent:
|
||||||
changed = semanage_boolean_value(module, name, state)
|
changed = semanage_boolean_value(module, name, state)
|
||||||
elif selinux.is_selinux_enabled():
|
else:
|
||||||
cur_value = get_boolean_value(module, name)
|
cur_value = get_boolean_value(module, name)
|
||||||
if cur_value != state:
|
if cur_value != state:
|
||||||
changed = True
|
changed = True
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue