mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ansible-config view fixes
This commit is contained in:
parent
de2096e3d0
commit
c51a4bc57d
2 changed files with 38 additions and 38 deletions
|
@ -26,7 +26,7 @@ import sys
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from ansible.cli import CLI
|
from ansible.cli import CLI
|
||||||
from ansible.config.manager import ConfigManager, Setting
|
from ansible.config.manager import ConfigManager, Setting, find_ini_config_file
|
||||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||||
from ansible.module_utils._text import to_native, to_text, to_bytes
|
from ansible.module_utils._text import to_native, to_text, to_bytes
|
||||||
from ansible.parsing.yaml.dumper import AnsibleDumper
|
from ansible.parsing.yaml.dumper import AnsibleDumper
|
||||||
|
@ -86,23 +86,23 @@ class ConfigCLI(CLI):
|
||||||
super(ConfigCLI, self).run()
|
super(ConfigCLI, self).run()
|
||||||
|
|
||||||
if self.options.config_file:
|
if self.options.config_file:
|
||||||
self.config_file = unfrackpath(self.options.config_file, follow=False)
|
self.config_file = to_bytes(unfrackpath(self.options.config_file, follow=False))
|
||||||
self.config = ConfigManager(self.config_file)
|
self.config = ConfigManager(self.config_file)
|
||||||
else:
|
else:
|
||||||
self.config = ConfigManager()
|
self.config = ConfigManager()
|
||||||
self.config_file = to_bytes(self.config.data.get_setting('ANSIBLE_CONFIG'))
|
self.config_file = to_bytes(find_ini_config_file())
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(self.config_file):
|
if not os.path.exists(self.config_file):
|
||||||
raise AnsibleOptionsError("%s does not exist or is not accessible" % (self.config_file))
|
raise AnsibleOptionsError("%s does not exist or is not accessible" % (self.config_file))
|
||||||
elif not os.path.isfile(self.config_file):
|
elif not os.path.isfile(self.config_file):
|
||||||
raise AnsibleOptionsError("%s is not a valid file" % (self.config_file))
|
raise AnsibleOptionsError("%s is not a valid file" % (self.config_file))
|
||||||
|
|
||||||
os.environ['ANSIBLE_CONFIG'] = self.config_file
|
os.environ['ANSIBLE_CONFIG'] = to_native(self.config_file)
|
||||||
except:
|
except:
|
||||||
if self.action in ['view']:
|
if self.action in ['view']:
|
||||||
raise
|
raise
|
||||||
elif self.action in ['edit', 'update']:
|
elif self.action in ['edit', 'update']:
|
||||||
display.warning("File does not exist, used empty file: %s" % self.config_file)
|
display.warning("File does not exist, used empty file: %s" % self.config_file)
|
||||||
|
|
||||||
self.execute()
|
self.execute()
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,29 @@ def get_ini_config_value(p, entry):
|
||||||
pass
|
pass
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def find_ini_config_file():
|
||||||
|
''' Load INI Config File order(first found is used): ENV, CWD, HOME, /etc/ansible '''
|
||||||
|
# FIXME: eventually deprecate ini configs
|
||||||
|
|
||||||
|
path0 = os.getenv("ANSIBLE_CONFIG", None)
|
||||||
|
if path0 is not None:
|
||||||
|
path0 = unfrackpath(path0, follow=False)
|
||||||
|
if os.path.isdir(path0):
|
||||||
|
path0 += "/ansible.cfg"
|
||||||
|
try:
|
||||||
|
path1 = os.getcwd() + "/ansible.cfg"
|
||||||
|
except OSError:
|
||||||
|
path1 = None
|
||||||
|
path2 = unfrackpath("~/.ansible.cfg", follow=False)
|
||||||
|
path3 = "/etc/ansible/ansible.cfg"
|
||||||
|
|
||||||
|
for path in [path0, path1, path2, path3]:
|
||||||
|
if path is not None and os.path.exists(path):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
path = None
|
||||||
|
|
||||||
|
return path
|
||||||
|
|
||||||
class ConfigManager(object):
|
class ConfigManager(object):
|
||||||
|
|
||||||
|
@ -145,7 +168,7 @@ class ConfigManager(object):
|
||||||
|
|
||||||
if self._config_file is None:
|
if self._config_file is None:
|
||||||
# set config using ini
|
# set config using ini
|
||||||
self._config_file = self._find_ini_config_file()
|
self._config_file = find_ini_config_file()
|
||||||
|
|
||||||
if self._config_file:
|
if self._config_file:
|
||||||
if os.path.exists(self._config_file):
|
if os.path.exists(self._config_file):
|
||||||
|
@ -182,29 +205,6 @@ class ConfigManager(object):
|
||||||
''' Load YAML Config Files in order, check merge flags, keep origin of settings'''
|
''' Load YAML Config Files in order, check merge flags, keep origin of settings'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _find_ini_config_file(self):
|
|
||||||
''' Load INI Config File order(first found is used): ENV, CWD, HOME, /etc/ansible '''
|
|
||||||
# FIXME: eventually deprecate ini configs
|
|
||||||
|
|
||||||
path0 = os.getenv("ANSIBLE_CONFIG", None)
|
|
||||||
if path0 is not None:
|
|
||||||
path0 = unfrackpath(path0, follow=False)
|
|
||||||
if os.path.isdir(path0):
|
|
||||||
path0 += "/ansible.cfg"
|
|
||||||
try:
|
|
||||||
path1 = os.getcwd() + "/ansible.cfg"
|
|
||||||
except OSError:
|
|
||||||
path1 = None
|
|
||||||
path2 = unfrackpath("~/.ansible.cfg", follow=False)
|
|
||||||
path3 = "/etc/ansible/ansible.cfg"
|
|
||||||
|
|
||||||
for path in [path0, path1, path2, path3]:
|
|
||||||
if path is not None and os.path.exists(path):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
path = None
|
|
||||||
|
|
||||||
return path
|
|
||||||
|
|
||||||
def get_configuration_definitions(self, plugin_type=None, name=None):
|
def get_configuration_definitions(self, plugin_type=None, name=None):
|
||||||
''' just list the possible settings, either base or for specific plugins or plugin '''
|
''' just list the possible settings, either base or for specific plugins or plugin '''
|
||||||
|
|
Loading…
Reference in a new issue