From 58e255c2d94949a09934a36ebb9fe4a0c7195231 Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Tue, 7 Nov 2017 14:11:52 +0100 Subject: [PATCH] Fix IndexError raised on galaxy-install This patch fixes IndexError, that may be raised When trying to install a role with `ansible-galaxy` in case of access error to roles directory. Issue: ansible/galaxy#149 --- lib/ansible/galaxy/role.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py index f0800ba3d95..509b601dbac 100644 --- a/lib/ansible/galaxy/role.py +++ b/lib/ansible/galaxy/role.py @@ -22,6 +22,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import errno import datetime import os import tarfile @@ -325,11 +326,10 @@ class GalaxyRole(object): installed = True except OSError as e: error = True - if e[0] == 13 and len(self.paths) > 1: + if e.errno == errno.EACCES and len(self.paths) > 1: current = self.paths.index(self.path) - nextidx = current + 1 - if len(self.paths) >= current: - self.path = self.paths[nextidx] + if len(self.paths) > current: + self.path = self.paths[current + 1] error = False if error: raise AnsibleError("Could not update files in %s: %s" % (self.path, str(e)))