mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 14:59:09 -07: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
|
||||
|
||||
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.module_utils._text import to_native, to_text, to_bytes
|
||||
from ansible.parsing.yaml.dumper import AnsibleDumper
|
||||
|
@ -86,23 +86,23 @@ class ConfigCLI(CLI):
|
|||
super(ConfigCLI, self).run()
|
||||
|
||||
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)
|
||||
else:
|
||||
self.config = ConfigManager()
|
||||
self.config_file = to_bytes(self.config.data.get_setting('ANSIBLE_CONFIG'))
|
||||
try:
|
||||
if not os.path.exists(self.config_file):
|
||||
raise AnsibleOptionsError("%s does not exist or is not accessible" % (self.config_file))
|
||||
elif not os.path.isfile(self.config_file):
|
||||
raise AnsibleOptionsError("%s is not a valid file" % (self.config_file))
|
||||
self.config_file = to_bytes(find_ini_config_file())
|
||||
try:
|
||||
if not os.path.exists(self.config_file):
|
||||
raise AnsibleOptionsError("%s does not exist or is not accessible" % (self.config_file))
|
||||
elif not os.path.isfile(self.config_file):
|
||||
raise AnsibleOptionsError("%s is not a valid file" % (self.config_file))
|
||||
|
||||
os.environ['ANSIBLE_CONFIG'] = self.config_file
|
||||
except:
|
||||
if self.action in ['view']:
|
||||
raise
|
||||
elif self.action in ['edit', 'update']:
|
||||
display.warning("File does not exist, used empty file: %s" % self.config_file)
|
||||
os.environ['ANSIBLE_CONFIG'] = to_native(self.config_file)
|
||||
except:
|
||||
if self.action in ['view']:
|
||||
raise
|
||||
elif self.action in ['edit', 'update']:
|
||||
display.warning("File does not exist, used empty file: %s" % self.config_file)
|
||||
|
||||
self.execute()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue