mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
PEP8 E712 fixes (#21916)
This commit is contained in:
@@ -208,9 +208,9 @@ def main():
|
||||
rc,raw_fs,err = module.run_command("%s -c /dev/null -o value -s TYPE %s" % (cmd, dev))
|
||||
fs = raw_fs.strip()
|
||||
|
||||
if fs == fstype and resizefs == False and not force:
|
||||
if fs == fstype and resizefs is False and not force:
|
||||
module.exit_json(changed=False)
|
||||
elif fs == fstype and resizefs == True:
|
||||
elif fs == fstype and resizefs is True:
|
||||
# Get dev and fs size and compare
|
||||
devsize_in_bytes = _get_dev_size(dev, module)
|
||||
fssize_in_bytes = _get_fs_size(fssize_cmd, dev, module)
|
||||
|
||||
@@ -211,14 +211,14 @@ def update_fw_settings(fw_zone, fw_settings):
|
||||
# masquerade handling
|
||||
#
|
||||
def get_masquerade_enabled(zone):
|
||||
if fw.queryMasquerade(zone) == True:
|
||||
if fw.queryMasquerade(zone) is True:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_masquerade_enabled_permanent(zone):
|
||||
fw_zone, fw_settings = get_fw_zone_settings(zone)
|
||||
if fw_settings.getMasquerade() == True:
|
||||
if fw_settings.getMasquerade() is True:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -507,7 +507,7 @@ def main():
|
||||
|
||||
## Check for firewalld running
|
||||
try:
|
||||
if fw.connected == False:
|
||||
if fw.connected is False:
|
||||
module.fail_json(msg='firewalld service must be running, or try with offline=true')
|
||||
except AttributeError:
|
||||
module.fail_json(msg="firewalld connection can't be established,\
|
||||
@@ -623,7 +623,7 @@ def main():
|
||||
msgs.append('Permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -633,7 +633,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -651,7 +651,7 @@ def main():
|
||||
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -661,7 +661,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -671,7 +671,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
|
||||
if changed == True:
|
||||
if changed is True:
|
||||
msgs.append("Changed service %s to %s" % (service, desired_state))
|
||||
|
||||
# FIXME - source type does not handle non-permanent mode, this was an
|
||||
@@ -679,7 +679,7 @@ def main():
|
||||
if source is not None:
|
||||
is_enabled = action_handler(get_source, (zone, source))
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -687,7 +687,7 @@ def main():
|
||||
changed=True
|
||||
msgs.append("Added %s to zone %s" % (source, zone))
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -749,7 +749,7 @@ def main():
|
||||
msgs.append('Permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -759,7 +759,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -776,7 +776,7 @@ def main():
|
||||
msgs.append('Non-permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -786,7 +786,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -796,7 +796,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
|
||||
if changed == True:
|
||||
if changed is True:
|
||||
msgs.append("Changed port %s to %s" % ("%s/%s" % (port, protocol), \
|
||||
desired_state))
|
||||
|
||||
@@ -853,7 +853,7 @@ def main():
|
||||
msgs.append('Permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -863,7 +863,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -880,7 +880,7 @@ def main():
|
||||
msgs.append('Non-permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -890,7 +890,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -900,7 +900,7 @@ def main():
|
||||
)
|
||||
changed=True
|
||||
|
||||
if changed == True:
|
||||
if changed is True:
|
||||
msgs.append("Changed rich_rule %s to %s" % (rich_rule, desired_state))
|
||||
|
||||
if interface is not None:
|
||||
@@ -948,7 +948,7 @@ def main():
|
||||
)
|
||||
msgs.append('Permanent operation')
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -956,7 +956,7 @@ def main():
|
||||
changed=True
|
||||
msgs.append("Changed %s to zone %s" % (interface, zone))
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -970,7 +970,7 @@ def main():
|
||||
)
|
||||
msgs.append('Non-permanent operation')
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -978,7 +978,7 @@ def main():
|
||||
changed=True
|
||||
msgs.append("Changed %s to zone %s" % (interface, zone))
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -1027,7 +1027,7 @@ def main():
|
||||
msgs.append('Permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -1035,7 +1035,7 @@ def main():
|
||||
changed=True
|
||||
msgs.append("Added masquerade to zone %s" % (zone))
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -1047,7 +1047,7 @@ def main():
|
||||
msgs.append('Non-permanent operation')
|
||||
|
||||
if desired_state == "enabled":
|
||||
if is_enabled == False:
|
||||
if is_enabled is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
@@ -1055,7 +1055,7 @@ def main():
|
||||
changed=True
|
||||
msgs.append("Added masquerade to zone %s" % (zone))
|
||||
elif desired_state == "disabled":
|
||||
if is_enabled == True:
|
||||
if is_enabled is True:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
|
||||
|
||||
@@ -241,11 +241,11 @@ def get_peers():
|
||||
uuid = value
|
||||
if key.lower() == 'state':
|
||||
state = value
|
||||
peers[hostname] = [ uuid, state ]
|
||||
peers[hostname] = [uuid, state]
|
||||
elif row.lower() == 'other names:':
|
||||
shortNames = True
|
||||
elif row != '' and shortNames == True:
|
||||
peers[row] = [ uuid, state ]
|
||||
elif row != '' and shortNames is True:
|
||||
peers[row] = [uuid, state]
|
||||
elif row == '':
|
||||
shortNames = False
|
||||
return peers
|
||||
|
||||
@@ -105,7 +105,7 @@ class Group(object):
|
||||
if key == 'gid' and kwargs[key] is not None:
|
||||
cmd.append('-g')
|
||||
cmd.append(kwargs[key])
|
||||
elif key == 'system' and kwargs[key] == True:
|
||||
elif key == 'system' and kwargs[key] is True:
|
||||
cmd.append('-r')
|
||||
cmd.append(self.name)
|
||||
return self.execute_command(cmd)
|
||||
@@ -190,8 +190,8 @@ class AIX(Group):
|
||||
cmd = [self.module.get_bin_path('mkgroup', True)]
|
||||
for key in kwargs:
|
||||
if key == 'gid' and kwargs[key] is not None:
|
||||
cmd.append('id='+kwargs[key])
|
||||
elif key == 'system' and kwargs[key] == True:
|
||||
cmd.append('id=' + kwargs[key])
|
||||
elif key == 'system' and kwargs[key] is True:
|
||||
cmd.append('-a')
|
||||
cmd.append(self.name)
|
||||
return self.execute_command(cmd)
|
||||
@@ -202,7 +202,7 @@ class AIX(Group):
|
||||
for key in kwargs:
|
||||
if key == 'gid':
|
||||
if kwargs[key] is not None and info[2] != int(kwargs[key]):
|
||||
cmd.append('id='+kwargs[key])
|
||||
cmd.append('id=' + kwargs[key])
|
||||
if len(cmd) == 1:
|
||||
return (None, '', '')
|
||||
if self.module.check_mode:
|
||||
@@ -275,9 +275,9 @@ class DarwinGroup(Group):
|
||||
cmd += [ '-o', 'create' ]
|
||||
if self.gid is not None:
|
||||
cmd += [ '-i', self.gid ]
|
||||
elif 'system' in kwargs and kwargs['system'] == True:
|
||||
elif 'system' in kwargs and kwargs['system'] is True:
|
||||
gid = self.get_lowest_available_system_gid()
|
||||
if gid != False:
|
||||
if gid is not False:
|
||||
self.gid = str(gid)
|
||||
cmd += [ '-i', self.gid ]
|
||||
cmd += [ '-L', self.name ]
|
||||
|
||||
@@ -206,10 +206,10 @@ def sanity_check(module,host,key,sshkeygen):
|
||||
except:
|
||||
pass
|
||||
|
||||
if stdout=='': #host not found
|
||||
if stdout == '': # host not found
|
||||
module.fail_json(msg="Host parameter does not match hashed host field in supplied key")
|
||||
|
||||
def search_for_host_key(module,host,key,hash_host,path,sshkeygen):
|
||||
def search_for_host_key(module, host, key, hash_host, path, sshkeygen):
|
||||
'''search_for_host_key(module,host,key,path,sshkeygen) -> (found,replace_or_add,found_line)
|
||||
|
||||
Looks up host and keytype in the known_hosts file path; if it's there, looks to see
|
||||
@@ -220,37 +220,37 @@ def search_for_host_key(module,host,key,hash_host,path,sshkeygen):
|
||||
if found=False, then replace is always False.
|
||||
sshkeygen is the path to ssh-keygen, found earlier with get_bin_path
|
||||
'''
|
||||
if os.path.exists(path)==False:
|
||||
if os.path.exists(path) is False:
|
||||
return False, False, None, key
|
||||
|
||||
sshkeygen_command=[sshkeygen,'-F',host,'-f',path]
|
||||
sshkeygen_command=[sshkeygen, '-F', host, '-f', path]
|
||||
|
||||
#openssh >=6.4 has changed ssh-keygen behaviour such that it returns
|
||||
#1 if no host is found, whereas previously it returned 0
|
||||
# openssh >=6.4 has changed ssh-keygen behaviour such that it returns
|
||||
# 1 if no host is found, whereas previously it returned 0
|
||||
rc,stdout,stderr=module.run_command(sshkeygen_command,
|
||||
check_rc=False)
|
||||
if stdout=='' and stderr=='' and (rc==0 or rc==1):
|
||||
return False, False, None, key #host not found, no other errors
|
||||
if rc!=0: #something went wrong
|
||||
check_rc = False)
|
||||
if stdout == '' and stderr == '' and (rc == 0 or rc == 1):
|
||||
return False, False, None, key # host not found, no other errors
|
||||
if rc != 0: # something went wrong
|
||||
module.fail_json(msg="ssh-keygen failed (rc=%d,stdout='%s',stderr='%s')" % (rc,stdout,stderr))
|
||||
|
||||
#If user supplied no key, we don't want to try and replace anything with it
|
||||
# If user supplied no key, we don't want to try and replace anything with it
|
||||
if key is None:
|
||||
return True, False, None, key
|
||||
|
||||
lines=stdout.split('\n')
|
||||
lines = stdout.split('\n')
|
||||
new_key = normalize_known_hosts_key(key)
|
||||
|
||||
sshkeygen_command.insert(1,'-H')
|
||||
rc,stdout,stderr=module.run_command(sshkeygen_command,check_rc=False)
|
||||
if rc not in (0, 1) or stderr != '': #something went wrong
|
||||
module.fail_json(msg="ssh-keygen failed to hash host (rc=%d,stdout='%s',stderr='%s')" % (rc,stdout,stderr))
|
||||
hashed_lines=stdout.split('\n')
|
||||
sshkeygen_command.insert(1, '-H')
|
||||
rc, stdout, stderr = module.run_command(sshkeygen_command, check_rc=False)
|
||||
if rc not in (0, 1) or stderr != '': # something went wrong
|
||||
module.fail_json(msg="ssh-keygen failed to hash host (rc=%d,stdout='%s',stderr='%s')" % (rc, stdout, stderr))
|
||||
hashed_lines = stdout.split('\n')
|
||||
|
||||
for lnum,l in enumerate(lines):
|
||||
if l=='':
|
||||
for lnum, l in enumerate(lines):
|
||||
if l == '':
|
||||
continue
|
||||
elif l[0]=='#': # info output from ssh-keygen; contains the line number where key was found
|
||||
elif l[0] == '#': # info output from ssh-keygen; contains the line number where key was found
|
||||
try:
|
||||
# This output format has been hardcoded in ssh-keygen since at least OpenSSH 4.0
|
||||
# It always outputs the non-localized comment before the found key
|
||||
@@ -259,18 +259,18 @@ def search_for_host_key(module,host,key,hash_host,path,sshkeygen):
|
||||
module.fail_json(msg="failed to parse output of ssh-keygen for line number: '%s'" % l)
|
||||
else:
|
||||
found_key = normalize_known_hosts_key(l)
|
||||
if hash_host==True:
|
||||
if found_key['host'][:3]=='|1|':
|
||||
if hash_host is True:
|
||||
if found_key['host'][:3] == '|1|':
|
||||
new_key['host']=found_key['host']
|
||||
else:
|
||||
hashed_host=normalize_known_hosts_key(hashed_lines[lnum])
|
||||
found_key['host']=hashed_host['host']
|
||||
key=key.replace(host,found_key['host'])
|
||||
if new_key==found_key: #found a match
|
||||
return True, False, found_line, key #found exactly the same key, don't replace
|
||||
elif new_key['type'] == found_key['type']: # found a different key for the same key type
|
||||
if new_key==found_key: # found a match
|
||||
return True, False, found_line, key # found exactly the same key, don't replace
|
||||
elif new_key['type'] == found_key['type']: # found a different key for the same key type
|
||||
return True, True, found_line, key
|
||||
#No match found, return found and replace, but no line
|
||||
# No match found, return found and replace, but no line
|
||||
return True, True, None, key
|
||||
|
||||
def normalize_known_hosts_key(key):
|
||||
|
||||
@@ -233,7 +233,7 @@ def main():
|
||||
else:
|
||||
if changed:
|
||||
try:
|
||||
if ubuntuMode==False:
|
||||
if ubuntuMode is False:
|
||||
apply_change(state, name)
|
||||
else:
|
||||
apply_change_ubuntu(state, name)
|
||||
|
||||
@@ -2207,7 +2207,7 @@ def main():
|
||||
|
||||
if user.user_exists():
|
||||
info = user.user_info()
|
||||
if info == False:
|
||||
if info is False:
|
||||
result['msg'] = "failed to look up user name: %s" % user.name
|
||||
result['failed'] = True
|
||||
result['uid'] = info[2]
|
||||
|
||||
Reference in New Issue
Block a user