Created
March 3, 2020 09:57
-
-
Save asquelt/774e3465b75a6b55c1b1b98def4ac2da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Copyright: (c) 2019, Andrew J. Huffman <ahuffman@redhat.com> | |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | |
ANSIBLE_METADATA = {'metadata_version': '1.1', | |
'status': ['preview'], | |
'supported_by': 'community'} | |
DOCUMENTATION = ''' | |
--- | |
module: scan_getsebool | |
short_description: Collects currently set SELinux booleans on a system | |
version_added: "2.9" | |
description: | |
- "Collects the currently set SELinux booleans on a system at the time the module is run." | |
- "This module presents the currently set values as ansible_facts" | |
author: | |
- konrad rzentarzewski (@asquelt) | |
''' | |
EXAMPLES = ''' | |
# Collect sebools and output parsed data | |
- name: "Collect sebools" | |
scan_getsebool: | |
''' | |
RETURN = ''' | |
ansible_facts.getsebool: | |
- key: abrt_anon_write | |
value: false | |
- key: abrt_handle_event | |
value: false | |
- key: abrt_upload_watch_anon_write | |
value: true | |
''' | |
from ansible.module_utils.basic import AnsibleModule | |
import os, re, subprocess | |
from os.path import isfile, isdir, join | |
def main(): | |
module_args = dict() | |
result = dict( | |
changed=False, | |
original_message='', | |
message='' | |
) | |
module = AnsibleModule( | |
argument_spec=module_args, | |
supports_check_mode=True | |
) | |
params = module.params | |
def get_sebool(): | |
re_disabled = re.compile(r'SELinux is disabled') | |
bools = list() | |
try: | |
out = subprocess.check_output(["/sbin/getsebool -a"], universal_newlines=True, shell=True) | |
except: | |
out = '' | |
for l in out.split('\n'): | |
if len(l) > 0 and re_disabled.search(l) is None: | |
kv = l.split(' --> ') | |
bools.append({ 'key': kv[0], 'value': True if kv[1]=='on' else False }) | |
return bools | |
# Do work | |
data = get_sebool() | |
# Build output | |
result = {'ansible_facts': {'getsebool': data}} | |
module.exit_json(**result) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment