Fixing config loading issues when the config has no [general] section

Fixed typo in help documentation

Fix up sanity errors and update converted modules

Remove unnecessary test playbook file
This commit is contained in:
John Westcott IV
2020-02-06 11:07:19 -05:00
committed by beeankha
parent 4fc2c58ae7
commit 018dd4c1c3
4 changed files with 44 additions and 33 deletions

View File

@@ -7,7 +7,7 @@ from ansible.module_utils.six import PY2
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.six.moves.http_cookiejar import CookieJar
from ansible.module_utils.six.moves.configparser import ConfigParser, NoOptionError
from ansible.module_utils.six.moves.configparser import ConfigParser, NoOptionError, MissingSectionHeaderError
from socket import gethostbyname
import re
from json import loads, dumps
@@ -137,8 +137,10 @@ class TowerModule(AnsibleModule):
if not access(config_path, R_OK):
raise ConfigFileException("The specified config file can not be read")
config.read(config_path)
if not config.has_section('general'):
# If the config has not sections we will get a MissingSectionHeaderError
try:
config.read(config_path)
except MissingSectionHeaderError:
self.warn("No general section in file, auto-appending")
with open(config_path, 'r') as f:
config.read_string('[general]\n%s' % f.read())