From d0d1158c5ef7c1f822e622bebd80eb9471285b0b Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Sat, 28 Jan 2017 00:12:11 -0800 Subject: [PATCH] PEP 8 cleanup. (#20789) * PEP 8 E703 cleanup. * PEP 8 E701 cleanup. * PEP 8 E711 cleanup. * PEP 8 W191 and E101 cleanup. --- contrib/inventory/abiquo.py | 4 +-- contrib/inventory/apache-libcloud.py | 4 +-- contrib/inventory/cloudstack.py | 2 +- contrib/inventory/consul_io.py | 2 +- contrib/inventory/ec2.py | 2 +- contrib/inventory/gce.py | 36 ++++++++++++------- contrib/inventory/linode.py | 2 +- contrib/inventory/mdt_dynamic_inventory.py | 4 +-- contrib/inventory/softlayer.py | 2 +- contrib/inventory/spacewalk.py | 12 +++---- contrib/inventory/vmware_inventory.py | 2 +- contrib/inventory/windows_azure.py | 2 +- contrib/inventory/zabbix.py | 4 +-- hacking/metadata-tool.py | 2 +- lib/ansible/galaxy/login.py | 2 +- lib/ansible/module_utils/azure_rm_common.py | 2 +- lib/ansible/module_utils/basic.py | 11 +++--- lib/ansible/module_utils/facts.py | 3 +- lib/ansible/modules/cloud/amazon/_ec2_vpc.py | 4 +-- .../modules/cloud/amazon/cloudfront_facts.py | 2 +- lib/ansible/modules/cloud/amazon/ec2.py | 2 +- lib/ansible/modules/cloud/amazon/ec2_ami.py | 4 +-- .../modules/cloud/amazon/ec2_asg_facts.py | 3 +- .../modules/cloud/amazon/ec2_elb_lb.py | 2 +- .../cloud/amazon/ec2_vpc_dhcp_options.py | 10 +++--- .../modules/cloud/amazon/ec2_vpc_vgw.py | 4 +-- .../modules/cloud/amazon/ec2_win_password.py | 2 +- .../modules/cloud/amazon/iam_policy.py | 6 ++-- lib/ansible/modules/cloud/amazon/route53.py | 8 ++--- lib/ansible/modules/cloud/amazon/s3.py | 2 +- lib/ansible/modules/cloud/azure/azure.py | 3 +- lib/ansible/modules/cloud/docker/_docker.py | 4 +-- lib/ansible/modules/cloud/google/gcpubsub.py | 2 +- .../modules/cloud/google/gcpubsub_facts.py | 2 +- lib/ansible/modules/cloud/misc/ovirt.py | 2 +- .../modules/cloud/openstack/os_project.py | 2 +- .../cloud/profitbricks/profitbricks.py | 3 +- .../profitbricks/profitbricks_datacenter.py | 3 +- .../cloud/profitbricks/profitbricks_nic.py | 3 +- .../cloud/profitbricks/profitbricks_volume.py | 3 +- .../profitbricks_volume_attachments.py | 3 +- lib/ansible/modules/cloud/softlayer/sl_vm.py | 8 ++--- .../modules/cloud/vmware/vsphere_guest.py | 3 +- lib/ansible/modules/clustering/consul_kv.py | 2 +- .../modules/database/mysql/mysql_user.py | 2 +- lib/ansible/modules/files/acl.py | 2 +- lib/ansible/modules/files/find.py | 3 +- lib/ansible/modules/files/unarchive.py | 6 ++-- .../modules/monitoring/circonus_annotation.py | 6 ++-- .../modules/monitoring/librato_annotation.py | 10 +++--- lib/ansible/modules/network/dnsimple.py | 12 ++++--- .../network/exoscale/exo_dns_record.py | 4 +-- lib/ansible/modules/network/snmp_facts.py | 4 +-- lib/ansible/modules/notification/sendgrid.py | 2 +- .../modules/packaging/language/pear.py | 3 +- lib/ansible/modules/packaging/os/layman.py | 6 ++-- .../modules/packaging/os/openbsd_pkg.py | 4 +-- .../modules/packaging/os/pkg5_publisher.py | 14 ++++---- lib/ansible/modules/packaging/os/swdepot.py | 2 +- lib/ansible/modules/system/firewalld.py | 32 ++++++++--------- lib/ansible/modules/system/gluster_volume.py | 6 ++-- lib/ansible/modules/system/lvol.py | 5 +-- lib/ansible/modules/system/user.py | 2 +- .../web_infrastructure/apache2_mod_proxy.py | 2 +- lib/ansible/plugins/callback/profile_tasks.py | 2 +- lib/ansible/plugins/filter/core.py | 2 +- lib/ansible/plugins/filter/mathstuff.py | 4 +-- lib/ansible/plugins/lookup/hashi_vault.py | 4 +-- lib/ansible/utils/cmd_functions.py | 2 +- .../utils/module_docs_fragments/infinibox.py | 2 +- test/sanity/pep8/legacy-files.txt | 20 ----------- test/sanity/pep8/legacy-ignore.txt | 5 --- 72 files changed, 184 insertions(+), 174 deletions(-) diff --git a/contrib/inventory/abiquo.py b/contrib/inventory/abiquo.py index f643503b17..34544b6c21 100755 --- a/contrib/inventory/abiquo.py +++ b/contrib/inventory/abiquo.py @@ -55,7 +55,7 @@ from ansible.module_utils.urls import open_url def api_get(link, config): try: - if link == None: + if link is None: url = config.get('api','uri') + config.get('api','login_path') headers = {"Accept": config.get('api','login_type')} else: @@ -148,7 +148,7 @@ def generate_inv_from_api(enterprise_entity,config): if ((config.getboolean('defaults', 'deployed_only') == True) and (vmcollection['state'] == 'NOT_ALLOCATED')): vm_state = False - if not vm_nic == None and vm_state: + if vm_nic is not None and vm_state: if vm_vapp not in inventory: inventory[vm_vapp] = {} inventory[vm_vapp]['children'] = [] diff --git a/contrib/inventory/apache-libcloud.py b/contrib/inventory/apache-libcloud.py index f85148fae1..0120d2bf81 100755 --- a/contrib/inventory/apache-libcloud.py +++ b/contrib/inventory/apache-libcloud.py @@ -297,7 +297,7 @@ class LibcloudInventory(object): ''' if key in my_dict: - my_dict[key].append(element); + my_dict[key].append(element) else: my_dict[key] = [element] @@ -358,4 +358,4 @@ def main(): LibcloudInventory() if __name__ == '__main__': - main() + main() diff --git a/contrib/inventory/cloudstack.py b/contrib/inventory/cloudstack.py index cde8dc8e64..23ae44fbc6 100755 --- a/contrib/inventory/cloudstack.py +++ b/contrib/inventory/cloudstack.py @@ -179,7 +179,7 @@ class CloudStackInventory(object): }) if nic['isdefault']: data['default_ip'] = nic['ipaddress'] - break; + break return data diff --git a/contrib/inventory/consul_io.py b/contrib/inventory/consul_io.py index 40b3d35eba..330d284911 100755 --- a/contrib/inventory/consul_io.py +++ b/contrib/inventory/consul_io.py @@ -399,7 +399,7 @@ class ConsulInventory(object): new_dict = {} for k, v in d.items(): - if v != None: + if v is not None: new_dict[self.to_safe(str(k))] = self.to_safe(str(v)) return new_dict diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index 46cdb5a690..c97ceaed31 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -442,7 +442,7 @@ class Ec2Inventory(object): # Do we need to exclude hosts that match a pattern? try: - pattern_exclude = config.get('ec2', 'pattern_exclude'); + pattern_exclude = config.get('ec2', 'pattern_exclude') if pattern_exclude and len(pattern_exclude) > 0: self.pattern_exclude = re.compile(pattern_exclude) else: diff --git a/contrib/inventory/gce.py b/contrib/inventory/gce.py index 3c5424fdb9..fdb9fba884 100755 --- a/contrib/inventory/gce.py +++ b/contrib/inventory/gce.py @@ -428,8 +428,10 @@ class GceInventory(object): if zones and zone not in zones: continue - if zone in groups: groups[zone].append(name) - else: groups[zone] = [name] + if zone in groups: + groups[zone].append(name) + else: + groups[zone] = [name] tags = node.extra['tags'] for t in tags: @@ -437,26 +439,36 @@ class GceInventory(object): tag = t[6:] else: tag = 'tag_%s' % t - if tag in groups: groups[tag].append(name) - else: groups[tag] = [name] + if tag in groups: + groups[tag].append(name) + else: + groups[tag] = [name] net = node.extra['networkInterfaces'][0]['network'].split('/')[-1] net = 'network_%s' % net - if net in groups: groups[net].append(name) - else: groups[net] = [name] + if net in groups: + groups[net].append(name) + else: + groups[net] = [name] machine_type = node.size - if machine_type in groups: groups[machine_type].append(name) - else: groups[machine_type] = [name] + if machine_type in groups: + groups[machine_type].append(name) + else: + groups[machine_type] = [name] image = node.image and node.image or 'persistent_disk' - if image in groups: groups[image].append(name) - else: groups[image] = [name] + if image in groups: + groups[image].append(name) + else: + groups[image] = [name] status = node.extra['status'] stat = 'status_%s' % status.lower() - if stat in groups: groups[stat].append(name) - else: groups[stat] = [name] + if stat in groups: + groups[stat].append(name) + else: + groups[stat] = [name] groups["_meta"] = meta diff --git a/contrib/inventory/linode.py b/contrib/inventory/linode.py index 8e331e2f6e..1f54ba605b 100755 --- a/contrib/inventory/linode.py +++ b/contrib/inventory/linode.py @@ -300,7 +300,7 @@ class LinodeInventory(object): def push(self, my_dict, key, element): """Pushed an element onto an array that may not have been defined in the dict.""" if key in my_dict: - my_dict[key].append(element); + my_dict[key].append(element) else: my_dict[key] = [element] diff --git a/contrib/inventory/mdt_dynamic_inventory.py b/contrib/inventory/mdt_dynamic_inventory.py index 7c7c557194..dd2f5b8eac 100644 --- a/contrib/inventory/mdt_dynamic_inventory.py +++ b/contrib/inventory/mdt_dynamic_inventory.py @@ -69,9 +69,9 @@ class MDTInventory(object): Gets host from MDT Database ''' if hostname: - query = "SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID where t1.Description = '%s'" % hostname + query = "SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID where t1.Description = '%s'" % hostname else: - query = 'SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID' + query = 'SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID' self._connect(query) # Configure to group name configured in Ansible Tower for this inventory diff --git a/contrib/inventory/softlayer.py b/contrib/inventory/softlayer.py index 43a1faa8c7..21c0f44197 100755 --- a/contrib/inventory/softlayer.py +++ b/contrib/inventory/softlayer.py @@ -95,7 +95,7 @@ class SoftLayerInventory(object): '''Push an element onto an array that may not have been defined in the dict''' if key in my_dict: - my_dict[key].append(element); + my_dict[key].append(element) else: my_dict[key] = [element] diff --git a/contrib/inventory/spacewalk.py b/contrib/inventory/spacewalk.py index a32ab8ea8d..20cbb14ab2 100755 --- a/contrib/inventory/spacewalk.py +++ b/contrib/inventory/spacewalk.py @@ -110,9 +110,9 @@ parser.add_option('-H', '--human', dest="human", default=False, action="store_true", help="Produce a friendlier version of either server list or host detail") parser.add_option('-o', '--org', default=None, dest="org_number", - help="Limit to spacewalk organization number") + help="Limit to spacewalk organization number") parser.add_option('-p', default=False, dest="prefix_org_name", action="store_true", - help="Prefix the group name with the organization number") + help="Prefix the group name with the organization number") (options, args) = parser.parse_args() @@ -133,13 +133,13 @@ if os.path.exists(INI_FILE): #------------------------------ org_groups = {} try: - for group in spacewalk_report('system-groups'): - org_groups[group['spacewalk_group_id']] = group['spacewalk_org_id'] + for group in spacewalk_report('system-groups'): + org_groups[group['spacewalk_group_id']] = group['spacewalk_org_id'] except (OSError) as e: - print('Problem executing the command "%s system-groups": %s' % + print('Problem executing the command "%s system-groups": %s' % (SW_REPORT, str(e)), file=sys.stderr) - sys.exit(2) + sys.exit(2) # List out the known server from Spacewalk diff --git a/contrib/inventory/vmware_inventory.py b/contrib/inventory/vmware_inventory.py index 84979dc270..86dfb2984a 100755 --- a/contrib/inventory/vmware_inventory.py +++ b/contrib/inventory/vmware_inventory.py @@ -374,7 +374,7 @@ class VMWareInventory(object): if cfm is not None and cfm.field: for f in cfm.field: if f.managedObjectType == vim.VirtualMachine: - self.custom_fields[f.key] = f.name; + self.custom_fields[f.key] = f.name self.debugl('%d custom fieds collected' % len(self.custom_fields)) return instance_tuples diff --git a/contrib/inventory/windows_azure.py b/contrib/inventory/windows_azure.py index d2999f1876..cceed36bcc 100755 --- a/contrib/inventory/windows_azure.py +++ b/contrib/inventory/windows_azure.py @@ -246,7 +246,7 @@ class AzureInventory(object): def push(self, my_dict, key, element): """Pushed an element onto an array that may not have been defined in the dict.""" if key in my_dict: - my_dict[key].append(element); + my_dict[key].append(element) else: my_dict[key] = [element] diff --git a/contrib/inventory/zabbix.py b/contrib/inventory/zabbix.py index 6d41df4d3e..4957764a3e 100755 --- a/contrib/inventory/zabbix.py +++ b/contrib/inventory/zabbix.py @@ -55,9 +55,9 @@ class ZabbixInventory(object): config = ConfigParser.SafeConfigParser() conf_path = './zabbix.ini' if not os.path.exists(conf_path): - conf_path = os.path.dirname(os.path.realpath(__file__)) + '/zabbix.ini' + conf_path = os.path.dirname(os.path.realpath(__file__)) + '/zabbix.ini' if os.path.exists(conf_path): - config.read(conf_path) + config.read(conf_path) # server if config.has_option('zabbix', 'server'): self.zabbix_server = config.get('zabbix', 'server') diff --git a/hacking/metadata-tool.py b/hacking/metadata-tool.py index e8737e5372..df0a2fb702 100755 --- a/hacking/metadata-tool.py +++ b/hacking/metadata-tool.py @@ -91,7 +91,7 @@ def seek_end_of_dict(module_data, start_line, start_col, next_node_line, next_no ANSIBLE_METADATA = {}EOF """ - if next_node_line == None: + if next_node_line is None: # The dict is the last statement in the file snippet = module_data.splitlines()[start_line:] next_node_col = 0 diff --git a/lib/ansible/galaxy/login.py b/lib/ansible/galaxy/login.py index d6bb0a6957..430035ca1f 100644 --- a/lib/ansible/galaxy/login.py +++ b/lib/ansible/galaxy/login.py @@ -50,7 +50,7 @@ class GalaxyLogin(object): self.github_username = None self.github_password = None - if github_token == None: + if github_token is None: self.get_credentials() def get_credentials(self): diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index 69bb26127a..7d2c7a1012 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -379,7 +379,7 @@ class AzureRMModuleBase(object): mod = importlib.import_module(module_name) for mod_class_name, mod_class_obj in inspect.getmembers(mod, predicate=inspect.isclass): dependencies[mod_class_name] = mod_class_obj - self.log("dependencies: "); + self.log("dependencies: ") self.log(str(dependencies)) serializer = Serializer(classes=dependencies) return serializer.body(obj, class_name) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 33933911fa..dcc64489bc 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1169,9 +1169,12 @@ class AnsibleModule(object): def _apply_operation_to_mode(self, user, operator, mode_to_apply, current_mode): if operator == '=': - if user == 'u': mask = stat.S_IRWXU | stat.S_ISUID - elif user == 'g': mask = stat.S_IRWXG | stat.S_ISGID - elif user == 'o': mask = stat.S_IRWXO | stat.S_ISVTX + if user == 'u': + mask = stat.S_IRWXU | stat.S_ISUID + elif user == 'g': + mask = stat.S_IRWXG | stat.S_ISGID + elif user == 'o': + mask = stat.S_IRWXO | stat.S_ISVTX # mask out u, g, or o permissions from current_mode and apply new permissions inverse_mask = mask ^ PERM_BITS @@ -2361,7 +2364,7 @@ class AnsibleModule(object): # No pipes are left to read but process is not yet terminated # Only then it is safe to wait for the process to be finished # NOTE: Actually cmd.poll() is always None here if rpipes is empty - elif not rpipes and cmd.poll() == None: + elif not rpipes and cmd.poll() is None: cmd.wait() # The process is terminated. Since no pipes to read from are # left, there is no need to call select() again. diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 72c775c111..616beff862 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2186,7 +2186,8 @@ class AIX(Hardware): # nfs or cifs based mount # in case of nfs if no mount options are provided on command line # add into fields empty string... - if len(fields) < 8: fields.append("") + if len(fields) < 8: + fields.append("") self.facts['mounts'].append({'mount': fields[2], 'device': '%s:%s' % (fields[0], fields[1]), 'fstype' : fields[3], diff --git a/lib/ansible/modules/cloud/amazon/_ec2_vpc.py b/lib/ansible/modules/cloud/amazon/_ec2_vpc.py index d5638c5054..50aa45c064 100644 --- a/lib/ansible/modules/cloud/amazon/_ec2_vpc.py +++ b/lib/ansible/modules/cloud/amazon/_ec2_vpc.py @@ -189,7 +189,7 @@ def find_vpc(module, vpc_conn, vpc_id=None, cidr=None): A VPC object that matches either an ID or CIDR and one or more tag values """ - if vpc_id == None and cidr == None: + if vpc_id is None and cidr is None: module.fail_json( msg='You must specify either a vpc_id or a cidr block + list of unique tags, aborting' ) @@ -565,7 +565,7 @@ def create_vpc(module, vpc_conn): old_rt = vpc_conn.get_all_route_tables( filters={'association.subnet_id': rsn.id, 'vpc_id': vpc.id} ) - old_rt = [ x for x in old_rt if x.id != None ] + old_rt = [ x for x in old_rt if x.id is not None ] if len(old_rt) == 1: old_rt = old_rt[0] association_id = None diff --git a/lib/ansible/modules/cloud/amazon/cloudfront_facts.py b/lib/ansible/modules/cloud/amazon/cloudfront_facts.py index ca59b9f7b2..bdead14981 100644 --- a/lib/ansible/modules/cloud/amazon/cloudfront_facts.py +++ b/lib/ansible/modules/cloud/amazon/cloudfront_facts.py @@ -410,7 +410,7 @@ def main(): list_origin_access_identities = module.params.get('list_origin_access_identities') list_distributions = module.params.get('list_distributions') - list_distributions_by_web_acl_id = module.params.get('list_distributions_by_web_acl_id'); + list_distributions_by_web_acl_id = module.params.get('list_distributions_by_web_acl_id') list_invalidations = module.params.get('list_invalidations') list_streaming_distributions = module.params.get('list_streaming_distributions') diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index 20c2b4215d..34a487f3f2 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -1040,7 +1040,7 @@ def create_instances(module, ec2, vpc, override_count=None): running_instances = [] count_remaining = int(count) - if id != None: + if id is not None: filter_dict = {'client-token':id, 'instance-state-name' : 'running'} previous_reservations = ec2.get_all_instances(None, filter_dict) for res in previous_reservations: diff --git a/lib/ansible/modules/cloud/amazon/ec2_ami.py b/lib/ansible/modules/cloud/amazon/ec2_ami.py index c3850a54f8..267d3187ff 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_ami.py +++ b/lib/ansible/modules/cloud/amazon/ec2_ami.py @@ -506,7 +506,7 @@ def deregister_image(module, ec2): wait_timeout = int(module.params.get('wait_timeout')) img = ec2.get_image(image_id) - if img == None: + if img is None: module.fail_json(msg = "Image %s does not exist" % image_id, changed=False) # Get all associated snapshot ids before deregistering image otherwise this information becomes unavailable @@ -562,7 +562,7 @@ def update_image(module, ec2, image_id): launch_permissions['user_ids'] = [str(user_id) for user_id in launch_permissions['user_ids']] img = ec2.get_image(image_id) - if img == None: + if img is None: module.fail_json(msg = "Image %s does not exist" % image_id, changed=False) try: diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py b/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py index 92d45f59c5..2e3dac9118 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py @@ -210,7 +210,8 @@ def match_asg_tags(tags_to_match, asg): for tag in asg['Tags']: if key == tag['Key'] and value == tag['Value']: break - else: return False + else: + return False return True def find_asgs(conn, module, name=None, tags=None): diff --git a/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py b/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py index 9e162c6b0e..3c97a420fc 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py +++ b/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py @@ -886,7 +886,7 @@ class ElbManager(object): self._disable_zones(zones_to_disable) def _set_security_groups(self): - if self.security_group_ids != None and set(self.elb.security_groups) != set(self.security_group_ids): + if self.security_group_ids is not None and set(self.elb.security_groups) != set(self.security_group_ids): self.elb_conn.apply_security_groups_to_lb(self.name, self.security_group_ids) self.changed = True diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options.py index ed2901d3e8..4dcbf43f78 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options.py @@ -298,16 +298,16 @@ def main(): # First check if we were given a dhcp_options_id if not params['dhcp_options_id']: # No, so create new_options from the parameters - if params['dns_servers'] != None: + if params['dns_servers'] is not None: new_options['domain-name-servers'] = params['dns_servers'] - if params['netbios_name_servers'] != None: + if params['netbios_name_servers'] is not None: new_options['netbios-name-servers'] = params['netbios_name_servers'] - if params['ntp_servers'] != None: + if params['ntp_servers'] is not None: new_options['ntp-servers'] = params['ntp_servers'] - if params['domain_name'] != None: + if params['domain_name'] is not None: # needs to be a list for comparison with boto objects later new_options['domain-name'] = [ params['domain_name'] ] - if params['netbios_node_type'] != None: + if params['netbios_node_type'] is not None: # needs to be a list for comparison with boto objects later new_options['netbios-node-type'] = [ str(params['netbios_node_type']) ] # If we were given a vpc_id then we need to look at the options on that diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py index 870b50cc72..38dffd8c25 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py @@ -312,14 +312,14 @@ def check_tags(client, module, existing_vgw, vpn_gateway_id): tags_list[tags['Key']] = tags['Value'] # if existing tags don't match the tags arg, delete existing and recreate with new list - if params['Tags'] != None and tags_list != params['Tags']: + if params['Tags'] is not None and tags_list != params['Tags']: delete_tags(client, module, vpn_gateway_id) create_tags(client, module, vpn_gateway_id) vgw = find_vgw(client, module) changed = True #if no tag args are supplied, delete any existing tags with the exception of the name tag - if params['Tags'] == None and tags_list != {}: + if params['Tags'] is None and tags_list != {}: tags_to_delete = [] for tags in existing_vgw[0]['Tags']: if tags['Key'] != 'Name': diff --git a/lib/ansible/modules/cloud/amazon/ec2_win_password.py b/lib/ansible/modules/cloud/amazon/ec2_win_password.py index c29b86cb85..bf89ea0ec8 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_win_password.py +++ b/lib/ansible/modules/cloud/amazon/ec2_win_password.py @@ -163,7 +163,7 @@ def main(): except ValueError as e: decrypted = None - if decrypted == None: + if decrypted is None: module.exit_json(win_password='', changed=False) else: if wait: diff --git a/lib/ansible/modules/cloud/amazon/iam_policy.py b/lib/ansible/modules/cloud/amazon/iam_policy.py index 97be3f4051..153ed35f42 100644 --- a/lib/ansible/modules/cloud/amazon/iam_policy.py +++ b/lib/ansible/modules/cloud/amazon/iam_policy.py @@ -304,14 +304,14 @@ def main(): policy_name = module.params.get('policy_name') skip = module.params.get('skip_duplicates') - if module.params.get('policy_document') != None and module.params.get('policy_json') != None: + if module.params.get('policy_document') is not None and module.params.get('policy_json') is not None: module.fail_json(msg='Only one of "policy_document" or "policy_json" may be set') - if module.params.get('policy_document') != None: + if module.params.get('policy_document') is not None: with open(module.params.get('policy_document'), 'r') as json_data: pdoc = json.dumps(json.load(json_data)) json_data.close() - elif module.params.get('policy_json') != None: + elif module.params.get('policy_json') is not None: pdoc = module.params.get('policy_json') # if its a string, assume it is already JSON if not isinstance(pdoc, basestring): diff --git a/lib/ansible/modules/cloud/amazon/route53.py b/lib/ansible/modules/cloud/amazon/route53.py index 266456e15b..67e09245e0 100644 --- a/lib/ansible/modules/cloud/amazon/route53.py +++ b/lib/ansible/modules/cloud/amazon/route53.py @@ -325,7 +325,7 @@ def get_zone_by_name(conn, module, zone_name, want_private, zone_id, want_vpc_id # only save this zone id if the private status of the zone matches # the private_zone_in boolean specified in the params private_zone = module.boolean(zone.config.get('PrivateZone', False)) - if private_zone == want_private and ((zone.name == zone_name and zone_id == None) or zone.id.replace('/hostedzone/', '') == zone_id): + if private_zone == want_private and ((zone.name == zone_name and zone_id is None) or zone.id.replace('/hostedzone/', '') == zone_id): if want_vpc_id: # NOTE: These details aren't available in other boto methods, hence the necessary # extra API call @@ -464,13 +464,13 @@ def main(): module.fail_json(msg = "parameter 'value' must contain a single dns name for alias create/delete") elif not alias_hosted_zone_id_in: module.fail_json(msg = "parameter 'alias_hosted_zone_id' required for alias create/delete") - elif ( weight_in!=None or region_in!=None or failover_in!=None ) and identifier_in==None: + elif ( weight_in is not None or region_in is not None or failover_in is not None ) and identifier_in is None: module.fail_json(msg= "If you specify failover, region or weight you must also specify identifier") if command_in == 'create': - if ( weight_in!=None or region_in!=None or failover_in!=None ) and identifier_in==None: + if ( weight_in is not None or region_in is not None or failover_in is not None ) and identifier_in is None: module.fail_json(msg= "If you specify failover, region or weight you must also specify identifier") - elif ( weight_in==None and region_in==None and failover_in==None ) and identifier_in!=None: + elif ( weight_in is None and region_in is None and failover_in is None ) and identifier_in is not None: module.fail_json(msg= "You have specified identifier which makes sense only if you specify one of: weight, region or failover.") diff --git a/lib/ansible/modules/cloud/amazon/s3.py b/lib/ansible/modules/cloud/amazon/s3.py index 9974a4f467..5fc29563a9 100755 --- a/lib/ansible/modules/cloud/amazon/s3.py +++ b/lib/ansible/modules/cloud/amazon/s3.py @@ -643,7 +643,7 @@ def main(): # Delete an object from a bucket, not the entire bucket if mode == 'delobj': if obj is None: - module.fail_json(msg="object parameter is required", failed=True); + module.fail_json(msg="object parameter is required", failed=True) if bucket: bucketrtn = bucket_check(module, s3, bucket) if bucketrtn is True: diff --git a/lib/ansible/modules/cloud/azure/azure.py b/lib/ansible/modules/cloud/azure/azure.py index 870533c9ae..77e43e27e6 100644 --- a/lib/ansible/modules/cloud/azure/azure.py +++ b/lib/ansible/modules/cloud/azure/azure.py @@ -276,7 +276,8 @@ from types import MethodType import json def _wait_for_completion(azure, promise, wait_timeout, msg): - if not promise: return + if not promise: + return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): operation_result = azure.get_operation_status(promise.request_id) diff --git a/lib/ansible/modules/cloud/docker/_docker.py b/lib/ansible/modules/cloud/docker/_docker.py index 714b306f3e..e9b7f0af0d 100644 --- a/lib/ansible/modules/cloud/docker/_docker.py +++ b/lib/ansible/modules/cloud/docker/_docker.py @@ -1553,12 +1553,12 @@ class DockerManager(object): image_matches = running_image in repo_tags - if command == None: + if command is None: command_matches = True else: command_matches = (command == details['Config']['Cmd']) - if entrypoint == None: + if entrypoint is None: entrypoint_matches = True else: entrypoint_matches = ( diff --git a/lib/ansible/modules/cloud/google/gcpubsub.py b/lib/ansible/modules/cloud/google/gcpubsub.py index 989d690390..814e07e6cd 100644 --- a/lib/ansible/modules/cloud/google/gcpubsub.py +++ b/lib/ansible/modules/cloud/google/gcpubsub.py @@ -176,7 +176,7 @@ try: from ast import literal_eval HAS_PYTHON26 = True except ImportError: - HAS_PYTHON26 = False; + HAS_PYTHON26 = False try: from google.cloud import pubsub diff --git a/lib/ansible/modules/cloud/google/gcpubsub_facts.py b/lib/ansible/modules/cloud/google/gcpubsub_facts.py index 7c943d85ea..13134c9396 100644 --- a/lib/ansible/modules/cloud/google/gcpubsub_facts.py +++ b/lib/ansible/modules/cloud/google/gcpubsub_facts.py @@ -88,7 +88,7 @@ try: from ast import literal_eval HAS_PYTHON26 = True except ImportError: - HAS_PYTHON26 = False; + HAS_PYTHON26 = False try: from google.cloud import pubsub diff --git a/lib/ansible/modules/cloud/misc/ovirt.py b/lib/ansible/modules/cloud/misc/ovirt.py index 6df53bed9c..d148503931 100644 --- a/lib/ansible/modules/cloud/misc/ovirt.py +++ b/lib/ansible/modules/cloud/misc/ovirt.py @@ -382,7 +382,7 @@ def vm_status(conn, vmname): # Get VM object and return it's name if object exists def get_vm(conn, vmname): vm = conn.vms.get(name=vmname) - if vm == None: + if vm is None: name = "empty" else: name = vm.get_name() diff --git a/lib/ansible/modules/cloud/openstack/os_project.py b/lib/ansible/modules/cloud/openstack/os_project.py index 22f5010755..7f75c14925 100644 --- a/lib/ansible/modules/cloud/openstack/os_project.py +++ b/lib/ansible/modules/cloud/openstack/os_project.py @@ -139,7 +139,7 @@ def _system_state_change(module, project): else: changed=True - return changed; + return changed def main(): diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks.py b/lib/ansible/modules/cloud/profitbricks/profitbricks.py index bcbecabe01..0f046be8e0 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks.py @@ -223,7 +223,8 @@ uuid_match = re.compile( def _wait_for_completion(profitbricks, promise, wait_timeout, msg): - if not promise: return + if not promise: + return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py index 6ad2fea75d..d062dcba7b 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py @@ -105,7 +105,8 @@ uuid_match = re.compile( def _wait_for_completion(profitbricks, promise, wait_timeout, msg): - if not promise: return + if not promise: + return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py index 358b7fba24..9644a6c130 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py @@ -107,7 +107,8 @@ uuid_match = re.compile( def _wait_for_completion(profitbricks, promise, wait_timeout, msg): - if not promise: return + if not promise: + return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py index 3708903114..5898a87177 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py @@ -157,7 +157,8 @@ uuid_match = re.compile( def _wait_for_completion(profitbricks, promise, wait_timeout, msg): - if not promise: return + if not promise: + return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py index 7848a02e15..3e29b1dbb9 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py @@ -105,7 +105,8 @@ uuid_match = re.compile( def _wait_for_completion(profitbricks, promise, wait_timeout, msg): - if not promise: return + if not promise: + return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) diff --git a/lib/ansible/modules/cloud/softlayer/sl_vm.py b/lib/ansible/modules/cloud/softlayer/sl_vm.py index 4696f47180..bb76a203b3 100644 --- a/lib/ansible/modules/cloud/softlayer/sl_vm.py +++ b/lib/ansible/modules/cloud/softlayer/sl_vm.py @@ -270,9 +270,9 @@ def create_virtual_instance(module): # Check if OS or Image Template is provided (Can't be both, defaults to OS) - if (module.params.get('os_code') != None and module.params.get('os_code') != ''): + if (module.params.get('os_code') is not None and module.params.get('os_code') != ''): module.params['image_id'] = '' - elif (module.params.get('image_id') != None and module.params.get('image_id') != ''): + elif (module.params.get('image_id') is not None and module.params.get('image_id') != ''): module.params['os_code'] = '' module.params['disks'] = [] # Blank out disks since it will use the template else: @@ -302,7 +302,7 @@ def create_virtual_instance(module): post_uri = module.params.get('post_uri'), tags = tags) - if instance != None and instance['id'] > 0: + if instance is not None and instance['id'] > 0: return True, instance else: return False, None @@ -325,7 +325,7 @@ def wait_for_instance(module,id): def cancel_instance(module): canceled = True - if module.params.get('instance_id') == None and (module.params.get('tags') or module.params.get('hostname') or module.params.get('domain')): + if module.params.get('instance_id') is None and (module.params.get('tags') or module.params.get('hostname') or module.params.get('domain')): tags = module.params.get('tags') if isinstance(tags, basestring): tags = [module.params.get('tags')] diff --git a/lib/ansible/modules/cloud/vmware/vsphere_guest.py b/lib/ansible/modules/cloud/vmware/vsphere_guest.py index 6bd7405bbe..7a5323c6a8 100644 --- a/lib/ansible/modules/cloud/vmware/vsphere_guest.py +++ b/lib/ansible/modules/cloud/vmware/vsphere_guest.py @@ -1190,7 +1190,8 @@ def _find_path_in_tree(tree, path): def _get_folderid_for_path(vsphere_client, datacenter, path): content = vsphere_client._retrieve_properties_traversal(property_names=['name', 'parent'], obj_type=MORTypes.Folder) - if not content: return {} + if not content: + return {} node_list = [ { diff --git a/lib/ansible/modules/clustering/consul_kv.py b/lib/ansible/modules/clustering/consul_kv.py index 1f3db18359..3f5cb9a4c8 100644 --- a/lib/ansible/modules/clustering/consul_kv.py +++ b/lib/ansible/modules/clustering/consul_kv.py @@ -234,7 +234,7 @@ def remove_value(module): index, existing = consul_api.kv.get( key, recurse=module.params.get('recurse')) - changed = existing != None + changed = existing is not None if changed and not module.check_mode: consul_api.kv.delete(key, module.params.get('recurse')) diff --git a/lib/ansible/modules/database/mysql/mysql_user.py b/lib/ansible/modules/database/mysql/mysql_user.py index 286106fe71..20f7675753 100644 --- a/lib/ansible/modules/database/mysql/mysql_user.py +++ b/lib/ansible/modules/database/mysql/mysql_user.py @@ -238,7 +238,7 @@ class InvalidPrivsError(Exception): # User Authentication Management was change in MySQL 5.7 # This is a generic check for if the server version is less than version 5.7 def server_version_check(cursor): - cursor.execute("SELECT VERSION()"); + cursor.execute("SELECT VERSION()") result = cursor.fetchone() version_str = result[0] version = version_str.split('.') diff --git a/lib/ansible/modules/files/acl.py b/lib/ansible/modules/files/acl.py index 6f3bbfaf60..c97f2a7b18 100644 --- a/lib/ansible/modules/files/acl.py +++ b/lib/ansible/modules/files/acl.py @@ -329,7 +329,7 @@ def main(): module.fail_json(msg="'entry' MUST NOT be set when 'state=query'.") default_flag, etype, entity, permissions = split_entry(entry) - if default_flag != None: + if default_flag is not None: default = default_flag if get_platform().lower() == 'freebsd': diff --git a/lib/ansible/modules/files/find.py b/lib/ansible/modules/files/find.py index f7ad3fa687..192f7cef43 100644 --- a/lib/ansible/modules/files/find.py +++ b/lib/ansible/modules/files/find.py @@ -227,7 +227,8 @@ def sizefilter(st, size): def contentfilter(fsname, pattern): '''filter files which contain the given expression''' - if pattern is None: return True + if pattern is None: + return True try: f = open(fsname) diff --git a/lib/ansible/modules/files/unarchive.py b/lib/ansible/modules/files/unarchive.py index f9d6baede6..745557054d 100644 --- a/lib/ansible/modules/files/unarchive.py +++ b/lib/ansible/modules/files/unarchive.py @@ -349,8 +349,10 @@ class ZipArchive(object): continue # Check first and seventh field in order to skip header/footer - if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue - if len(pcs[6]) != 15: continue + if len(pcs[0]) != 7 and len(pcs[0]) != 10: + continue + if len(pcs[6]) != 15: + continue # Possible entries: # -rw-rws--- 1.9 unx 2802 t- defX 11-Aug-91 13:48 perms.2660 diff --git a/lib/ansible/modules/monitoring/circonus_annotation.py b/lib/ansible/modules/monitoring/circonus_annotation.py index 0f9c28c652..2bbf7de762 100644 --- a/lib/ansible/modules/monitoring/circonus_annotation.py +++ b/lib/ansible/modules/monitoring/circonus_annotation.py @@ -109,15 +109,15 @@ def post_annotation(annotation, api_key): def create_annotation(module): ''' Takes ansible module object ''' annotation = {} - if module.params['duration'] != None: + if module.params['duration'] is not None: duration = module.params['duration'] else: duration = 0 - if module.params['start'] != None: + if module.params['start'] is not None: start = module.params['start'] else: start = int(time.time()) - if module.params['stop'] != None: + if module.params['stop'] is not None: stop = module.params['stop'] else: stop = int(time.time())+ duration diff --git a/lib/ansible/modules/monitoring/librato_annotation.py b/lib/ansible/modules/monitoring/librato_annotation.py index 838abf14e6..cadade1ef4 100644 --- a/lib/ansible/modules/monitoring/librato_annotation.py +++ b/lib/ansible/modules/monitoring/librato_annotation.py @@ -117,15 +117,15 @@ def post_annotation(module): params = {} params['title'] = title - if module.params['source'] != None: + if module.params['source'] is not None: params['source'] = module.params['source'] - if module.params['description'] != None: + if module.params['description'] is not None: params['description'] = module.params['description'] - if module.params['start_time'] != None: + if module.params['start_time'] is not None: params['start_time'] = module.params['start_time'] - if module.params['end_time'] != None: + if module.params['end_time'] is not None: params['end_time'] = module.params['end_time'] - if module.params['links'] != None: + if module.params['links'] is not None: params['links'] = module.params['links'] json_body = module.jsonify(params) diff --git a/lib/ansible/modules/network/dnsimple.py b/lib/ansible/modules/network/dnsimple.py index 3f6c2188b0..bb87430319 100644 --- a/lib/ansible/modules/network/dnsimple.py +++ b/lib/ansible/modules/network/dnsimple.py @@ -276,8 +276,10 @@ def main(): # check if we need to update if rr['ttl'] != ttl or rr['prio'] != priority: data = {} - if ttl: data['ttl'] = ttl - if priority: data['prio'] = priority + if ttl: + data['ttl'] = ttl + if priority: + data['prio'] = priority if module.check_mode: module.exit_json(changed=True) else: @@ -291,8 +293,10 @@ def main(): 'record_type': record_type, 'content': value, } - if ttl: data['ttl'] = ttl - if priority: data['prio'] = priority + if ttl: + data['ttl'] = ttl + if priority: + data['prio'] = priority if module.check_mode: module.exit_json(changed=True) else: diff --git a/lib/ansible/modules/network/exoscale/exo_dns_record.py b/lib/ansible/modules/network/exoscale/exo_dns_record.py index 495508d3d4..c76c1c7a0f 100644 --- a/lib/ansible/modules/network/exoscale/exo_dns_record.py +++ b/lib/ansible/modules/network/exoscale/exo_dns_record.py @@ -332,9 +332,9 @@ class ExoDnsRecord(ExoDns): def present_record(self): record = self.get_record() if not record: - record = self._create_record(record); + record = self._create_record(record) else: - record = self._update_record(record); + record = self._update_record(record) return record def absent_record(self): diff --git a/lib/ansible/modules/network/snmp_facts.py b/lib/ansible/modules/network/snmp_facts.py index 034c5f5b91..3e4cfc6c30 100644 --- a/lib/ansible/modules/network/snmp_facts.py +++ b/lib/ansible/modules/network/snmp_facts.py @@ -209,10 +209,10 @@ def main(): module.fail_json(msg='Community not set when using snmp version 2') if m_args['version'] == "v3": - if m_args['username'] == None: + if m_args['username'] is None: module.fail_json(msg='Username not set when using snmp version 3') - if m_args['level'] == "authPriv" and m_args['privacy'] == None: + if m_args['level'] == "authPriv" and m_args['privacy'] is None: module.fail_json(msg='Privacy algorithm not set when using authPriv') diff --git a/lib/ansible/modules/notification/sendgrid.py b/lib/ansible/modules/notification/sendgrid.py index b0821983dc..4b5b9b1617 100644 --- a/lib/ansible/modules/notification/sendgrid.py +++ b/lib/ansible/modules/notification/sendgrid.py @@ -252,7 +252,7 @@ def main(): sendgrid_lib_args = [api_key, bcc, cc, headers, from_name, html_body, attachments] - if any(lib_arg != None for lib_arg in sendgrid_lib_args) and not HAS_SENDGRID: + if any(lib_arg is not None for lib_arg in sendgrid_lib_args) and not HAS_SENDGRID: module.fail_json(msg='You must install the sendgrid python library if you want to use any of the following arguments: api_key, bcc, cc, headers, from_name, html_body, attachments') response, info = post_sendgrid_api(module, username, password, diff --git a/lib/ansible/modules/packaging/language/pear.py b/lib/ansible/modules/packaging/language/pear.py index 98df9f2a21..44e856f4aa 100644 --- a/lib/ansible/modules/packaging/language/pear.py +++ b/lib/ansible/modules/packaging/language/pear.py @@ -77,7 +77,8 @@ def get_local_version(pear_output): for line in lines: if 'Installed ' in line: installed = line.rsplit(None, 1)[-1].strip() - if installed == '-': continue + if installed == '-': + continue return installed return None diff --git a/lib/ansible/modules/packaging/os/layman.py b/lib/ansible/modules/packaging/os/layman.py index 9c46cf3190..aad3051dc9 100644 --- a/lib/ansible/modules/packaging/os/layman.py +++ b/lib/ansible/modules/packaging/os/layman.py @@ -103,7 +103,8 @@ except ImportError: HAS_LAYMAN_API = False -class ModuleError(Exception): pass +class ModuleError(Exception): + pass def init_layman(config=None): @@ -201,7 +202,8 @@ def uninstall_overlay(module, name): module.exit_json(changed=True, msg=mymsg) layman.delete_repos(name) - if layman.get_errors(): raise ModuleError(layman.get_errors()) + if layman.get_errors(): + raise ModuleError(layman.get_errors()) return True diff --git a/lib/ansible/modules/packaging/os/openbsd_pkg.py b/lib/ansible/modules/packaging/os/openbsd_pkg.py index 24089e61de..eb47eac143 100644 --- a/lib/ansible/modules/packaging/os/openbsd_pkg.py +++ b/lib/ansible/modules/packaging/os/openbsd_pkg.py @@ -161,9 +161,9 @@ def get_package_state(names, pkg_spec, module): # find multiple packages with that name. pkg_spec[name]['installed_names'] = [installed_name for installed_name in stdout.splitlines()] module.debug("get_package_state(): installed_names = %s" % pkg_spec[name]['installed_names']) - pkg_spec[name]['installed_state'] = True; + pkg_spec[name]['installed_state'] = True else: - pkg_spec[name]['installed_state'] = False; + pkg_spec[name]['installed_state'] = False # Function used to make sure a package is present. def package_present(names, pkg_spec, module): diff --git a/lib/ansible/modules/packaging/os/pkg5_publisher.py b/lib/ansible/modules/packaging/os/pkg5_publisher.py index 279b40f009..ddc3e9cb80 100644 --- a/lib/ansible/modules/packaging/os/pkg5_publisher.py +++ b/lib/ansible/modules/packaging/os/pkg5_publisher.py @@ -111,7 +111,7 @@ def modify_publisher(module, params): if name in existing: for option in ['origin', 'mirror', 'sticky', 'enabled']: - if params[option] != None: + if params[option] is not None: if params[option] != existing[name][option]: return set_publisher(module, params) else: @@ -124,21 +124,21 @@ def set_publisher(module, params): name = params['name'] args = [] - if params['origin'] != None: + if params['origin'] is not None: args.append('--remove-origin=*') args.extend(['--add-origin=' + u for u in params['origin']]) - if params['mirror'] != None: + if params['mirror'] is not None: args.append('--remove-mirror=*') args.extend(['--add-mirror=' + u for u in params['mirror']]) - if params['sticky'] != None and params['sticky']: + if params['sticky'] is not None and params['sticky']: args.append('--sticky') - elif params['sticky'] != None: + elif params['sticky'] is not None: args.append('--non-sticky') - if params['enabled'] != None and params['enabled']: + if params['enabled'] is not None and params['enabled']: args.append('--enable') - elif params['enabled'] != None: + elif params['enabled'] is not None: args.append('--disable') rc, out, err = module.run_command( diff --git a/lib/ansible/modules/packaging/os/swdepot.py b/lib/ansible/modules/packaging/os/swdepot.py index 3da3f443c5..c155960faa 100644 --- a/lib/ansible/modules/packaging/os/swdepot.py +++ b/lib/ansible/modules/packaging/os/swdepot.py @@ -140,7 +140,7 @@ def main(): changed = False msg = "No changed" rc = 0 - if ( state == 'present' or state == 'latest' ) and depot == None: + if ( state == 'present' or state == 'latest' ) and depot is None: output = "depot parameter is mandatory in present or latest task" module.fail_json(name=name, msg=output, rc=rc) diff --git a/lib/ansible/modules/system/firewalld.py b/lib/ansible/modules/system/firewalld.py index 8324069b1b..ec42682962 100644 --- a/lib/ansible/modules/system/firewalld.py +++ b/lib/ansible/modules/system/firewalld.py @@ -515,10 +515,10 @@ def main(): ## Verify required params are provided - if module.params['source'] == None and module.params['permanent'] == None: + if module.params['source'] is None and module.params['permanent'] is None: module.fail_json(msg='permanent is a required parameter') - if module.params['interface'] != None and module.params['zone'] == None: + if module.params['interface'] is not None and module.params['zone'] is None: module.fail(msg='zone is a required parameter') if module.params['immediate'] and fw_offline: @@ -531,14 +531,14 @@ def main(): rich_rule = module.params['rich_rule'] source = module.params['source'] - if module.params['port'] != None: + if module.params['port'] is not None: port, protocol = module.params['port'].split('/') - if protocol == None: + if protocol is None: module.fail_json(msg='improper port format (missing protocol?)') else: port = None - if module.params['zone'] != None: + if module.params['zone'] is not None: zone = module.params['zone'] else: if fw_offline: @@ -554,21 +554,21 @@ def main(): masquerade = module.params['masquerade'] modification_count = 0 - if service != None: + if service is not None: modification_count += 1 - if port != None: + if port is not None: modification_count += 1 - if rich_rule != None: + if rich_rule is not None: modification_count += 1 - if interface != None: + if interface is not None: modification_count += 1 - if masquerade != None: + if masquerade is not None: modification_count += 1 if modification_count > 1: module.fail_json(msg='can only operate on port, service, rich_rule or interface at once') - if service != None: + if service is not None: if immediate and permanent: is_enabled_permanent = action_handler( get_service_enabled_permanent, @@ -676,7 +676,7 @@ def main(): # FIXME - source type does not handle non-permanent mode, this was an # oversight in the past. - if source != None: + if source is not None: is_enabled = action_handler(get_source, (zone, source)) if desired_state == "enabled": if is_enabled == False: @@ -695,7 +695,7 @@ def main(): changed=True msgs.append("Removed %s from zone %s" % (source, zone)) - if port != None: + if port is not None: if immediate and permanent: is_enabled_permanent = action_handler( get_port_enabled_permanent, @@ -800,7 +800,7 @@ def main(): msgs.append("Changed port %s to %s" % ("%s/%s" % (port, protocol), \ desired_state)) - if rich_rule != None: + if rich_rule is not None: if immediate and permanent: is_enabled_permanent = action_handler( get_rich_rule_enabled_permanent, @@ -903,7 +903,7 @@ def main(): if changed == True: msgs.append("Changed rich_rule %s to %s" % (rich_rule, desired_state)) - if interface != None: + if interface is not None: if immediate and permanent: is_enabled_permanent = action_handler( get_interface_permanent, @@ -986,7 +986,7 @@ def main(): changed=True msgs.append("Removed %s from zone %s" % (interface, zone)) - if masquerade != None: + if masquerade is not None: if immediate and permanent: is_enabled_permanent = action_handler( diff --git a/lib/ansible/modules/system/gluster_volume.py b/lib/ansible/modules/system/gluster_volume.py index 185133c40a..8af22eb124 100644 --- a/lib/ansible/modules/system/gluster_volume.py +++ b/lib/ansible/modules/system/gluster_volume.py @@ -436,13 +436,13 @@ def main(): # Clean up if last element is empty. Consider that yml can look like this: # cluster="{% for host in groups['glusterfs'] %}{{ hostvars[host]['private_ip'] }},{% endfor %}" - if cluster != None and len(cluster) > 1 and cluster[-1] == '': + if cluster is not None and len(cluster) > 1 and cluster[-1] == '': cluster = cluster[0:-1] - if cluster == None or cluster[0] == '': + if cluster is None or cluster[0] == '': cluster = [myhostname] - if brick_paths != None and "," in brick_paths: + if brick_paths is not None and "," in brick_paths: brick_paths = brick_paths.split(",") else: brick_paths = [brick_paths] diff --git a/lib/ansible/modules/system/lvol.py b/lib/ansible/modules/system/lvol.py index 105e62c650..b7fe179289 100644 --- a/lib/ansible/modules/system/lvol.py +++ b/lib/ansible/modules/system/lvol.py @@ -262,7 +262,7 @@ def main(): # Determine if the "--yes" option should be used version_found = get_lvm_version(module) - if version_found == None: + if version_found is None: module.fail_json(msg="Failed to get LVM version number") version_yesopt = mkversion(2, 2, 99) # First LVM with the "--yes" option if version_found >= version_yesopt: @@ -320,7 +320,8 @@ def main(): try: float(size) - if not size[0].isdigit(): raise ValueError() + if not size[0].isdigit(): + raise ValueError() except ValueError: module.fail_json(msg="Bad size specification of '%s'" % size) diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index 1b3198de4b..721c5d57f9 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -1953,7 +1953,7 @@ class AIX(User): else: (rc2, out2, err2) = (None, '', '') - if rc != None: + if rc is not None: return (rc, out+out2, err+err2) else: return (rc2, out+out2, err+err2) diff --git a/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py b/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py index 4d2f2c39a8..71ae8a0b48 100644 --- a/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py +++ b/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py @@ -374,7 +374,7 @@ def main(): if HAS_BEAUTIFULSOUP is False: module.fail_json(msg="python module 'BeautifulSoup' is required!") - if module.params['state'] != None: + if module.params['state'] is not None: states = module.params['state'].split(',') if (len(states) > 1) and (("present" in states) or ("enabled" in states)): module.fail_json(msg="state present/enabled is mutually exclusive with other states!") diff --git a/lib/ansible/plugins/callback/profile_tasks.py b/lib/ansible/plugins/callback/profile_tasks.py index a8a4742e0d..644dd51748 100644 --- a/lib/ansible/plugins/callback/profile_tasks.py +++ b/lib/ansible/plugins/callback/profile_tasks.py @@ -82,7 +82,7 @@ class CallbackModule(CallbackBase): self.task_output_limit = os.getenv('PROFILE_TASKS_TASK_OUTPUT_LIMIT', 20) if self.sort_order == 'ascending': - self.sort_order = False; + self.sort_order = False if self.task_output_limit == 'all': self.task_output_limit = None diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index de7f334889..db0662df69 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -265,7 +265,7 @@ def get_encrypted_password(password, hashtype='sha512', salt=None): encrypted = crypt.crypt(password, saltstring) else: if hashtype == 'blowfish': - cls = passlib.hash.bcrypt; + cls = passlib.hash.bcrypt else: cls = getattr(passlib.hash, '%s_crypt' % hashtype) diff --git a/lib/ansible/plugins/filter/mathstuff.py b/lib/ansible/plugins/filter/mathstuff.py index 0800f317e1..a1b4ade78a 100644 --- a/lib/ansible/plugins/filter/mathstuff.py +++ b/lib/ansible/plugins/filter/mathstuff.py @@ -65,11 +65,11 @@ def union(a, b): def min(a): _min = __builtins__.get('min') - return _min(a); + return _min(a) def max(a): _max = __builtins__.get('max') - return _max(a); + return _max(a) def logarithm(x, base=math.e): diff --git a/lib/ansible/plugins/lookup/hashi_vault.py b/lib/ansible/plugins/lookup/hashi_vault.py index 74719967bc..72378f5dbc 100644 --- a/lib/ansible/plugins/lookup/hashi_vault.py +++ b/lib/ansible/plugins/lookup/hashi_vault.py @@ -50,12 +50,12 @@ class HashiVault: self.url = kwargs.get('url', ANSIBLE_HASHI_VAULT_ADDR) self.token = kwargs.get('token') - if self.token==None: + if self.token is None: raise AnsibleError("No Vault Token specified") # split secret arg, which has format 'secret/hello:value' into secret='secret/hello' and secret_field='value' s = kwargs.get('secret') - if s==None: + if s is None: raise AnsibleError("No secret specified") s_f = s.split(':') diff --git a/lib/ansible/utils/cmd_functions.py b/lib/ansible/utils/cmd_functions.py index 80937e4148..8038af03d7 100644 --- a/lib/ansible/utils/cmd_functions.py +++ b/lib/ansible/utils/cmd_functions.py @@ -75,7 +75,7 @@ def run_cmd(cmd, live=False, readsize=10): if (not rpipes or not rfd) and p.poll() is not None: break # Calling wait while there are still pipes to read can cause a lock - elif not rpipes and p.poll() == None: + elif not rpipes and p.poll() is None: p.wait() return p.returncode, stdout, stderr diff --git a/lib/ansible/utils/module_docs_fragments/infinibox.py b/lib/ansible/utils/module_docs_fragments/infinibox.py index abc08b6eb6..cd3834d5e4 100644 --- a/lib/ansible/utils/module_docs_fragments/infinibox.py +++ b/lib/ansible/utils/module_docs_fragments/infinibox.py @@ -19,7 +19,7 @@ class ModuleDocFragment(object): - # Standard Infinibox documentation fragment + # Standard Infinibox documentation fragment DOCUMENTATION = ''' options: system: diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 30cb12a9cd..5f31e7597a 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -1,5 +1,4 @@ contrib/inventory/abiquo.py -contrib/inventory/apache-libcloud.py contrib/inventory/azure_rm.py contrib/inventory/cloudstack.py contrib/inventory/consul_io.py @@ -7,17 +6,12 @@ contrib/inventory/digital_ocean.py contrib/inventory/docker.py contrib/inventory/ec2.py contrib/inventory/gce.py -contrib/inventory/linode.py contrib/inventory/mdt_dynamic_inventory.py contrib/inventory/openvz.py contrib/inventory/rax.py contrib/inventory/softlayer.py -contrib/inventory/spacewalk.py contrib/inventory/ssh_config.py contrib/inventory/vbox.py -contrib/inventory/vmware_inventory.py -contrib/inventory/windows_azure.py -contrib/inventory/zabbix.py contrib/inventory/zone.py docs/api/conf.py docs/docsite/conf.py @@ -38,7 +32,6 @@ lib/ansible/errors/__init__.py lib/ansible/executor/play_iterator.py lib/ansible/executor/stats.py lib/ansible/executor/task_executor.py -lib/ansible/galaxy/login.py lib/ansible/galaxy/role.py lib/ansible/inventory/dir.py lib/ansible/inventory/script.py @@ -180,7 +173,6 @@ lib/ansible/modules/cloud/openstack/_quantum_subnet.py lib/ansible/modules/cloud/openstack/os_auth.py lib/ansible/modules/cloud/openstack/os_nova_host_aggregate.py lib/ansible/modules/cloud/openstack/os_object.py -lib/ansible/modules/cloud/openstack/os_project.py lib/ansible/modules/cloud/openstack/os_quota.py lib/ansible/modules/cloud/openstack/os_recordset.py lib/ansible/modules/cloud/openstack/os_zone.py @@ -188,9 +180,6 @@ lib/ansible/modules/cloud/packet/packet_device.py lib/ansible/modules/cloud/packet/packet_sshkey.py lib/ansible/modules/cloud/profitbricks/profitbricks.py lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py -lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py -lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py -lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py lib/ansible/modules/cloud/softlayer/sl_vm.py lib/ansible/modules/cloud/vmware/vca_fw.py lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -240,7 +229,6 @@ lib/ansible/modules/messaging/rabbitmq_binding.py lib/ansible/modules/messaging/rabbitmq_exchange.py lib/ansible/modules/messaging/rabbitmq_queue.py lib/ansible/modules/monitoring/boundary_meter.py -lib/ansible/modules/monitoring/circonus_annotation.py lib/ansible/modules/monitoring/datadog_monitor.py lib/ansible/modules/monitoring/librato_annotation.py lib/ansible/modules/monitoring/logicmonitor.py @@ -338,18 +326,15 @@ lib/ansible/modules/packaging/language/bundler.py lib/ansible/modules/packaging/language/composer.py lib/ansible/modules/packaging/language/cpanm.py lib/ansible/modules/packaging/language/maven_artifact.py -lib/ansible/modules/packaging/language/pear.py lib/ansible/modules/packaging/os/apt.py lib/ansible/modules/packaging/os/apt_key.py lib/ansible/modules/packaging/os/apt_rpm.py lib/ansible/modules/packaging/os/dnf.py lib/ansible/modules/packaging/os/dpkg_selections.py lib/ansible/modules/packaging/os/homebrew.py -lib/ansible/modules/packaging/os/layman.py lib/ansible/modules/packaging/os/openbsd_pkg.py lib/ansible/modules/packaging/os/opkg.py lib/ansible/modules/packaging/os/pacman.py -lib/ansible/modules/packaging/os/pkg5_publisher.py lib/ansible/modules/packaging/os/pkgin.py lib/ansible/modules/packaging/os/pkgng.py lib/ansible/modules/packaging/os/portinstall.py @@ -446,15 +431,12 @@ lib/ansible/plugins/callback/dense.py lib/ansible/plugins/callback/foreman.py lib/ansible/plugins/callback/logentries.py lib/ansible/plugins/callback/oneline.py -lib/ansible/plugins/callback/profile_tasks.py lib/ansible/plugins/callback/selective.py lib/ansible/plugins/connection/accelerate.py lib/ansible/plugins/connection/paramiko_ssh.py lib/ansible/plugins/connection/ssh.py lib/ansible/plugins/connection/winrm.py -lib/ansible/plugins/filter/core.py lib/ansible/plugins/filter/ipaddr.py -lib/ansible/plugins/filter/mathstuff.py lib/ansible/plugins/lookup/dig.py lib/ansible/plugins/lookup/dnstxt.py lib/ansible/plugins/lookup/first_found.py @@ -467,14 +449,12 @@ lib/ansible/plugins/strategy/__init__.py lib/ansible/plugins/strategy/debug.py lib/ansible/plugins/strategy/linear.py lib/ansible/template/__init__.py -lib/ansible/utils/cmd_functions.py lib/ansible/utils/encrypt.py lib/ansible/utils/module_docs.py lib/ansible/utils/module_docs_fragments/aws.py lib/ansible/utils/module_docs_fragments/azure_tags.py lib/ansible/utils/module_docs_fragments/ec2.py lib/ansible/utils/module_docs_fragments/files.py -lib/ansible/utils/module_docs_fragments/infinibox.py lib/ansible/utils/module_docs_fragments/netapp.py lib/ansible/utils/module_docs_fragments/ovirt.py lib/ansible/utils/module_docs_fragments/ovirt_facts.py diff --git a/test/sanity/pep8/legacy-ignore.txt b/test/sanity/pep8/legacy-ignore.txt index 05512ff0ab..62cbeb82dc 100644 --- a/test/sanity/pep8/legacy-ignore.txt +++ b/test/sanity/pep8/legacy-ignore.txt @@ -1,4 +1,3 @@ -E101 E111 E114 E115 @@ -9,9 +8,5 @@ E126 E129 E131 E501 -E701 -E703 -E711 E712 E721 -W191