-
-
Save Red5d/20850a108df2f2b3a989 to your computer and use it in GitHub Desktop.
Ansible module to manage the PBIS config
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/env python | |
# Author: Red5d | |
# Date: 8/11/2014 | |
# | |
# Description: Ansible module to manage the PBIS config. | |
# | |
# Examples: | |
# | |
# Get all current PBIS config settings and put them into the pbis_output variable: | |
# - pbis: get=all | |
# register pbis_output | |
# | |
# Set the login shell for new users to /bin/bash: | |
# - pbis: name=LoginShellTemplate value=/bin/bash | |
# | |
import sys | |
import json | |
import os | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
get = dict(choices=['all'], required=False), | |
name = dict(required=False), | |
value = dict(required=False), | |
likewise = dict(required=False, default=False, choices=BOOLEANS) | |
), | |
supports_check_mode = True | |
) | |
get = module.params.get('get') | |
name = module.params.get('name') | |
value = module.params.get('value') | |
likewise = module.params.get('likewise') | |
if likewise == True: | |
config_command = "/opt/likewise/bin/lwconfig" | |
else: | |
config_command = "/opt/pbis/bin/config" | |
if get == "all": | |
if True: | |
values = [] | |
settings = os.popen(config_command+" --dump").read() | |
for item in settings.split('\n'): | |
itemValue=item.split(' ')[1:len(item.split(' '))] | |
values.append(str(itemValue).replace('"', '').replace('\\\\', '\\').replace('\\\\', '\\').replace("'", "").replace('[', '').replace(']', '').replace(',', '')) | |
print json.dumps({ | |
"AllowDeleteTo": values[0], | |
"AllowReadTo" : values[1], | |
"AllowWriteTo":values[2], | |
"MaxDiskUsage" : values[3], | |
"MaxEventLifespan": values[4], | |
"MaxNumEvents": values[5], | |
"DomainSeparator": values[6], | |
"SpaceReplacement": values[7], | |
"EnableEventlog": values[8], | |
"Providers": values[9], | |
"DisplayMotd": values[10], | |
"PAMLogLevel": values[11], | |
"UserNotAllowedError": values[12], | |
"AssumeDefaultDomain": values[13], | |
"CreateHomeDir": values[14], | |
"CreateK5Login": values[15], | |
"SyncSystemTime": values[16], | |
"TrimUserMembership": values[17], | |
"LdapSignAndSeal": values[18], | |
"LogADNetworkConnectionEvents": values[19], | |
"NssEnumerationEnabled": values[20], | |
"NssGroupMembersQueryCacheOnly": values[21], | |
"NssUserMembershipQueryCacheOnly": values[22], | |
"RefreshUserCredentials": values[23], | |
"CacheEntryExpiry": values[24], | |
"DomainManagerCheckDomainOnlineInterval": values[25], | |
"DomainManagerUnknownDomainCacheTimeout": values[26], | |
"MachinePasswordLifespan": values[27], | |
"MemoryCacheSizeCap": values[28], | |
"HomeDirPrefix": values[29], | |
"HomeDirTemplate": values[30], | |
"RemoteHomeDirTemplate": values[31], | |
"HomeDirUmask": values[32], | |
"LoginShellTemplate": values[33], | |
"SkeletonDirs": values[34], | |
"UserDomainPrefix": values[35], | |
"DomainManagerIgnoreAllTrusts": values[36], | |
"DomainManagerIncludeTrustsList": values[37], | |
"DomainManagerExcludeTrustsList": values[38], | |
"RequireMembershipOf": values[39], | |
"Local_AcceptNTLMv1": values[40], | |
"Local_HomeDirTemplate": values[41], | |
"Local_HomeDirUmask": values[42], | |
"Local_LoginShellTemplate": values[43], | |
"Local_SkeletonDirs": values[44], | |
"UserMonitorCheckInterval": values[45], | |
"LsassAutostart": values[46], | |
"EventlogAutostart": values[47] | |
}) | |
elif name != "": | |
setting = os.popen(config_command+" --dump | grep ^"+name).read() | |
setting = setting.replace('"', '').replace('\n', '') | |
compareString = name+" "+value | |
if str(compareString) == str(setting): | |
print json.dumps({ | |
"changed": False | |
}) | |
else: | |
if module.check_mode: | |
module.exit_json(changed=True, msg=compareString) | |
os.popen(config_command+" "+name+" "+value) | |
setting2 = os.popen(config_command+" --dump | grep ^"+name).read() | |
setting2 = setting2.replace('"', '').replace('\n', '') | |
if setting2 != compareString: | |
module.fail_json(msg="Invalid setting.") | |
else: | |
module.exit_json(changed=True, msg=compareString) | |
from ansible.module_utils.basic import * | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment