Capture only IOError when reading shebang from inventory file, to avoid ignoring other possible exceptions like timeouts from a task
This commit is contained in:
parent
388827a636
commit
37ae5aab31
1 changed files with 7 additions and 8 deletions
|
@ -105,19 +105,18 @@ class Inventory(object):
|
||||||
# class we can show a more apropos error
|
# class we can show a more apropos error
|
||||||
shebang_present = False
|
shebang_present = False
|
||||||
try:
|
try:
|
||||||
inv_file = open(host_list)
|
with open(host_list, "r") as inv_file:
|
||||||
first_line = inv_file.readlines()[0]
|
first_line = inv_file.readline()
|
||||||
inv_file.close()
|
if first_line.startswith("#!"):
|
||||||
if first_line.startswith('#!'):
|
shebang_present = True
|
||||||
shebang_present = True
|
except IOError:
|
||||||
except:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if utils.is_executable(host_list):
|
if utils.is_executable(host_list):
|
||||||
try:
|
try:
|
||||||
self.parser = InventoryScript(filename=host_list)
|
self.parser = InventoryScript(filename=host_list)
|
||||||
self.groups = self.parser.groups.values()
|
self.groups = self.parser.groups.values()
|
||||||
except:
|
except errors.AnsibleError:
|
||||||
if not shebang_present:
|
if not shebang_present:
|
||||||
raise errors.AnsibleError("The file %s is marked as executable, but failed to execute correctly. " % host_list + \
|
raise errors.AnsibleError("The file %s is marked as executable, but failed to execute correctly. " % host_list + \
|
||||||
"If this is not supposed to be an executable script, correct this with `chmod -x %s`." % host_list)
|
"If this is not supposed to be an executable script, correct this with `chmod -x %s`." % host_list)
|
||||||
|
@ -127,7 +126,7 @@ class Inventory(object):
|
||||||
try:
|
try:
|
||||||
self.parser = InventoryParser(filename=host_list)
|
self.parser = InventoryParser(filename=host_list)
|
||||||
self.groups = self.parser.groups.values()
|
self.groups = self.parser.groups.values()
|
||||||
except:
|
except errors.AnsibleError:
|
||||||
if shebang_present:
|
if shebang_present:
|
||||||
raise errors.AnsibleError("The file %s looks like it should be an executable inventory script, but is not marked executable. " % host_list + \
|
raise errors.AnsibleError("The file %s looks like it should be an executable inventory script, but is not marked executable. " % host_list + \
|
||||||
"Perhaps you want to correct this with `chmod +x %s`?" % host_list)
|
"Perhaps you want to correct this with `chmod +x %s`?" % host_list)
|
||||||
|
|
Loading…
Reference in a new issue