mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Make ini parsing slightly more robust
Prior to this commit, the ini parser would fail if the inventory was not 100% utf-8. This commit makes this slightly more robust by omitting full line comments from that requirement. Fixes #17593
This commit is contained in:
parent
74b7590211
commit
23305540b4
3 changed files with 30 additions and 22 deletions
|
@ -45,11 +45,10 @@ def get_file_parser(hostsfile, groups, loader):
|
|||
parser = None
|
||||
|
||||
try:
|
||||
inv_file = open(hostsfile)
|
||||
first_line = inv_file.readlines()[0]
|
||||
inv_file.close()
|
||||
if first_line.startswith('#!'):
|
||||
shebang_present = True
|
||||
with open(hostsfile, 'rb') as inv_file:
|
||||
initial_chars = inv_file.read(2)
|
||||
if initial_chars.startswith(b'#!'):
|
||||
shebang_present = True
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue