diff --git a/lib/ansible/runner/action_plugins/fetch.py b/lib/ansible/runner/action_plugins/fetch.py index a33152ac788..e7afa7d955d 100644 --- a/lib/ansible/runner/action_plugins/fetch.py +++ b/lib/ansible/runner/action_plugins/fetch.py @@ -64,8 +64,8 @@ class ActionModule(object): # if dest does not start with "/", we'll assume a relative path dest = utils.path_dwim(self.runner.basedir, dest) else: - # files are saved in dest dir, with a subdir for each host, then the filename - dest = "%s/%s/%s" % (utils.path_dwim(self.runner.basedir, dest), conn.host, source) + # files are saved in dest dir, with a subdir for each host, then the filename + dest = "%s/%s/%s" % (utils.path_dwim(self.runner.basedir, dest), conn.host, source) dest = dest.replace("//","/") # calculate md5 sum for the remote file diff --git a/library/cloud/glance_image b/library/cloud/glance_image index e6ec43befe1..25730cf7bc7 100644 --- a/library/cloud/glance_image +++ b/library/cloud/glance_image @@ -144,7 +144,7 @@ def _get_glance_client(module, kwargs): 'token': token, } try: - client = glanceclient.Client('1', endpoint, **kwargs) + client = glanceclient.Client('1', endpoint, **kwargs) except Exception as e: module.fail_json(msg = "Error in connecting to glance: %s" %e.message) return client @@ -179,7 +179,7 @@ def _glance_image_create(module, params, client): break time.sleep(5) except Exception as e: - module.fail_json(msg = "Error in creating image: %s" %e.message ) + module.fail_json(msg = "Error in creating image: %s" %e.message) if image.status == 'active': module.exit_json(changed = True, result = image.status, id=image.id) else: @@ -197,38 +197,38 @@ def _glance_delete_image(module, params, client): def main(): module = AnsibleModule( - argument_spec = dict( - login_username = dict(default='admin'), - login_password = dict(required=True), - login_tenant_name = dict(required=True), - auth_url = dict(default='http://127.0.0.1:35357/v2.0/'), - region_name = dict(default=None), - name = dict(required=True), - disk_format = dict(default='qcow2', choices=['aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso']), - container_format = dict(default='bare', choices=['aki', 'ari', 'bare', 'ovf']), - owner = dict(default=None), - min_disk = dict(default=None), - min_ram = dict(default=None), - is_public = dict(default=True), - copy_from = dict(default= None), - timeout = dict(default=180), - file = dict(default=None), - state = dict(default='present', choices=['absent', 'present']) + argument_spec = dict( + login_username = dict(default='admin'), + login_password = dict(required=True), + login_tenant_name = dict(required=True), + auth_url = dict(default='http://127.0.0.1:35357/v2.0/'), + region_name = dict(default=None), + name = dict(required=True), + disk_format = dict(default='qcow2', choices=['aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso']), + container_format = dict(default='bare', choices=['aki', 'ari', 'bare', 'ovf']), + owner = dict(default=None), + min_disk = dict(default=None), + min_ram = dict(default=None), + is_public = dict(default=True), + copy_from = dict(default= None), + timeout = dict(default=180), + file = dict(default=None), + state = dict(default='present', choices=['absent', 'present']) ), - mutually_exclusive = [['file','copy_from']], + mutually_exclusive = [['file','copy_from']], ) if module.params['state'] == 'present': if not module.params['file'] and not module.params['copy_from']: module.fail_json(msg = "Either file or copy_from variable should be set to create the image") client = _get_glance_client(module, module.params) - id = _glance_image_present(module, module.params, client) + id = _glance_image_present(module, module.params, client) if not id: _glance_image_create(module, module.params, client) module.exit_json(changed = False, id = id, result = "success") if module.params['state'] == 'absent': client = _get_glance_client(module, module.params) - id = _glance_image_present(module, module.params, client) + id = _glance_image_present(module, module.params, client) if not id: module.exit_json(changed = False, result = "Success") else: diff --git a/library/cloud/nova_compute b/library/cloud/nova_compute index 48aeceed0fe..a257353b5f6 100644 --- a/library/cloud/nova_compute +++ b/library/cloud/nova_compute @@ -152,7 +152,7 @@ def _create_server(module, nova): if not module.params['key_name']: del bootkwargs['key_name'] try: - server = nova.servers.create(*bootargs, **bootkwargs ) + server = nova.servers.create(*bootargs, **bootkwargs) server = nova.servers.get(server.id) except Exception as e: module.fail_json( msg = "Error in creating instance: %s " % e.message) diff --git a/library/cloud/quantum_floating_ip b/library/cloud/quantum_floating_ip index 20f14d4100b..84a87a0044a 100644 --- a/library/cloud/quantum_floating_ip +++ b/library/cloud/quantum_floating_ip @@ -107,7 +107,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = "Error in connecting to quantum: %s " % e.message) return quantum @@ -214,7 +214,7 @@ def main(): fixed_ip, port_id = _get_port_info(quantum, module, server_info['id']) if not port_id: module.fail_json(msg = "Cannot find a port for this instance, maybe fixed ip is not assigned") - floating_id, floating_ip = _get_floating_ip(module, quantum, fixed_ip) + floating_id, floating_ip = _get_floating_ip(module, quantum, fixed_ip) if module.params['state'] == 'present': if floating_ip: module.exit_json(changed = False, public_ip=floating_ip) diff --git a/library/cloud/quantum_floating_ip_associate b/library/cloud/quantum_floating_ip_associate index 3ed36c2ca2b..8fe48811bd0 100644 --- a/library/cloud/quantum_floating_ip_associate +++ b/library/cloud/quantum_floating_ip_associate @@ -107,7 +107,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = "Error in connecting to quantum: %s " % e.message) return quantum @@ -119,30 +119,30 @@ def _get_server_state(module, nova): for server in nova.servers.list(): if server: info = server._info - if info['name'] == module.params['instance_name']: - if info['status'] != 'ACTIVE' and module.params['state'] == 'present': - module.fail_json( msg="The VM is available but not Active. state:" + info['status']) - server_info = info - break + if info['name'] == module.params['instance_name']: + if info['status'] != 'ACTIVE' and module.params['state'] == 'present': + module.fail_json(msg="The VM is available but not Active. state:" + info['status']) + server_info = info + break except Exception as e: module.fail_json(msg = "Error in getting the server list: %s" % e.message) return server_info, server def _get_port_id(quantum, module, instance_id): kwargs = { - device_id': instance_id, + device_id': instance_id, } try: - ports = quantum.list_ports(**kwargs) + ports = quantum.list_ports(**kwargs) except Exception as e: - module.fail_json( msg = "Error in listing ports: %s" % e.message) + module.fail_json( msg = "Error in listing ports: %s" % e.message) if not ports['ports']: - return None + return None return ports['ports'][0]['id'] def _get_floating_ip_id(module, quantum): kwargs = { - 'floating_ip_address': module.params['ip_address'] + 'floating_ip_address': module.params['ip_address'] } try: ips = quantum.list_floatingips(**kwargs) @@ -152,14 +152,14 @@ def _get_floating_ip_id(module, quantum): module.fail_json(msg = "Could find the ip specified in parameter, Please check") ip = ips['floatingips'][0]['id'] if not ips['floatingips'][0]['port_id']: - state = "detached" + state = "detached" else: state = "attached" return state, ip def _update_floating_ip(quantum, module, port_id, floating_ip_id): kwargs = { - 'port_id': port_id + 'port_id': port_id } try: result = quantum.update_floatingip(floating_ip_id, {'floatingip': kwargs}) diff --git a/library/cloud/quantum_network b/library/cloud/quantum_network index 4c51d6c623d..e940049c69d 100644 --- a/library/cloud/quantum_network +++ b/library/cloud/quantum_network @@ -139,7 +139,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = " Error in connecting to quantum: %s " %e.message) return quantum @@ -154,7 +154,7 @@ def _set_tenant_id(module): for tenant in _os_keystone.tenants.list(): if tenant.name == tenant_name: _os_tenant_id = tenant.id - break; + break if not _os_tenant_id: module.fail_json(msg = "The tenant id cannot be found, please check the paramters") diff --git a/library/cloud/quantum_router b/library/cloud/quantum_router index addf8df9774..117f0767fc9 100644 --- a/library/cloud/quantum_router +++ b/library/cloud/quantum_router @@ -112,7 +112,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = "Error in connecting to quantum: %s " % e.message) return quantum @@ -127,7 +127,7 @@ def _set_tenant_id(module): for tenant in _os_keystone.tenants.list(): if tenant.name == login_tenant_name: _os_tenant_id = tenant.id - break; + break if not _os_tenant_id: module.fail_json(msg = "The tenant id cannot be found, please check the paramters") @@ -152,9 +152,9 @@ def _create_router(module, quantum): 'admin_state_up': module.params['admin_state_up'], } try: - new_router = quantum.create_router({'router': router }) + new_router = quantum.create_router(dict(router=router)) except Exception as e: - module.fail_json( msg = "Error in creating router: %s" % e.message) + module.fail_json( msg = "Error in creating router: %s" % e.message) return new_router['router']['id'] def _delete_router(module, quantum, router_id): @@ -191,14 +191,11 @@ def main(): else: router_id = _get_router_id(module, quantum) if not router_id: - module.exit_json(changed = False, result = "success" ) + module.exit_json(changed = False, result = "success") else: _delete_router(module, quantum, router_id) - module.exit_json(changed = True, result = "deleted" ) + module.exit_json(changed = True, result = "deleted") - - - # this is magic, see lib/ansible/module.params['common.py #<> main() diff --git a/library/cloud/quantum_router_gateway b/library/cloud/quantum_router_gateway index bf830aaf7d1..57dfc6202c3 100644 --- a/library/cloud/quantum_router_gateway +++ b/library/cloud/quantum_router_gateway @@ -105,7 +105,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = "Error in connecting to quantum: %s " % e.message) return quantum diff --git a/library/cloud/quantum_router_interface b/library/cloud/quantum_router_interface index 0271dc6c355..efcdf71b580 100644 --- a/library/cloud/quantum_router_interface +++ b/library/cloud/quantum_router_interface @@ -112,7 +112,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = "Error in connecting to quantum: %s " % e.message) return quantum @@ -126,15 +126,15 @@ def _set_tenant_id(module): for tenant in _os_keystone.tenants.list(): if tenant.name == login_tenant_name: - _os_tenant_id = tenant.id - break; + _os_tenant_id = tenant.id + break if not _os_tenant_id: module.fail_json(msg = "The tenant id cannot be found, please check the paramters") def _get_router_id(module, quantum): kwargs = { - 'name': module.params['router_name'], + 'name': module.params['router_name'], } try: routers = quantum.list_routers(**kwargs) diff --git a/library/cloud/quantum_subnet b/library/cloud/quantum_subnet index ced58993887..8723c39d40f 100644 --- a/library/cloud/quantum_subnet +++ b/library/cloud/quantum_subnet @@ -140,7 +140,7 @@ def _get_quantum_client(module, kwargs): 'endpoint_url': endpoint } try: - quantum = client.Client('2.0', **kwargs) + quantum = client.Client('2.0', **kwargs) except Exception as e: module.fail_json(msg = " Error in connecting to quantum: %s" % e.message) return quantum @@ -155,7 +155,7 @@ def _set_tenant_id(module): for tenant in _os_keystone.tenants.list(): if tenant.name == tenant_name: _os_tenant_id = tenant.id - break; + break if not _os_tenant_id: module.fail_json(msg = "The tenant id cannot be found, please check the paramters") @@ -204,17 +204,19 @@ def _create_subnet(module, quantum): 'cidr': module.params['cidr'], } if module.params['allocation_pool_start'] and module.params['allocation_pool_end']: - allocation_pools = [ - {'start': module.params['allocation_pool_start'], - 'end': module.params['allocation_pool_end']} - ] - subnet.update({'allocation_pools': allocation_pools}) + allocation_pools = [ + { + 'start' : module.params['allocation_pool_start'], + 'end' : module.params['allocation_pool_end'] + } + ] + subnet.update({'allocation_pools': allocation_pools}) if not module.params['gateway_ip']: - subnet.pop('gateway_ip') + subnet.pop('gateway_ip') try: - new_subnet = quantum.create_subnet({'subnet': subnet }) - except Exception as e: - module.fail_json( msg = "Failure in creating subnet: %s" %e.message) + new_subnet = quantum.create_subnet(dict(subnet=subnet)) + except Exception, e: + module.fail_json(msg = "Failure in creating subnet: %s" % e.message) return new_subnet['subnet']['id'] @@ -229,22 +231,22 @@ def _delete_subnet(module, quantum, subnet_id): def main(): module = AnsibleModule( - argument_spec = dict( - login_username = dict(default='admin'), - login_password = dict(required=True), - login_tenant_name = dict(required='True'), - auth_url = dict(default='http://127.0.0.1:35357/v2.0/'), - region_name = dict(default=None), - name = dict(required=True), - network_name = dict(required=True), - cidr = dict(required=True), - tenant_name = dict(default=None), - state = dict(default='present', choices=['absent', 'present']), - ip_version = dict(default='4', choices=['4', '6']), - enable_dhcp = dict(default='true', choices=BOOLEANS), - gateway_ip = dict(default=None), - allocation_pool_start = dict(default=None), - allocation_pool_end = dict(default=None), + argument_spec = dict( + login_username = dict(default='admin'), + login_password = dict(required=True), + login_tenant_name = dict(required='True'), + auth_url = dict(default='http://127.0.0.1:35357/v2.0/'), + region_name = dict(default=None), + name = dict(required=True), + network_name = dict(required=True), + cidr = dict(required=True), + tenant_name = dict(default=None), + state = dict(default='present', choices=['absent', 'present']), + ip_version = dict(default='4', choices=['4', '6']), + enable_dhcp = dict(default='true', choices=BOOLEANS), + gateway_ip = dict(default=None), + allocation_pool_start = dict(default=None), + allocation_pool_end = dict(default=None), ), ) quantum = _get_quantum_client(module, module.params) @@ -259,10 +261,10 @@ def main(): else: subnet_id = _get_subnet_id(module, quantum) if not subnet_id: - module.exit_json(changed = False, result = "success" ) + module.exit_json(changed = False, result = "success") else: - _delete_subnet(module, quantum, subnet_id) - module.exit_json(changed = True, result = "deleted" ) + _delete_subnet(module, quantum, subnet_id) + module.exit_json(changed = True, result = "deleted") # this is magic, see lib/ansible/module.params['common.py #<> diff --git a/library/packaging/apt_repository b/library/packaging/apt_repository index e35048f0684..6e3b98fd854 100644 --- a/library/packaging/apt_repository +++ b/library/packaging/apt_repository @@ -112,9 +112,9 @@ def main(): # deb http://myserver/path/to/repo free non-free for i in repo_url.split(): for prot in ['http', 'file', 'ftp']: - if prot in i: - repo_url = i - break + if prot in i: + repo_url = i + break exists = repo_exists(module, repo_url) rc = 0