2012-02-29 01:08:09 +01:00
|
|
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-03-05 22:06:02 +01:00
|
|
|
import os
|
2012-08-11 23:33:34 +02:00
|
|
|
import pwd
|
2012-08-14 01:17:14 +02:00
|
|
|
import ConfigParser
|
|
|
|
import traceback
|
2012-03-05 22:06:02 +01:00
|
|
|
|
2012-08-14 01:17:14 +02:00
|
|
|
def get_config(p, section, key, env_var, default):
|
2012-10-17 00:40:01 +02:00
|
|
|
if env_var is not None:
|
2012-10-18 04:34:59 +02:00
|
|
|
value = os.environ.get(env_var, None)
|
|
|
|
if value is not None:
|
|
|
|
return value
|
2012-08-14 01:17:14 +02:00
|
|
|
if p is not None:
|
|
|
|
try:
|
|
|
|
return p.get(section, key)
|
|
|
|
except:
|
|
|
|
return default
|
2012-10-19 02:27:39 +02:00
|
|
|
return default
|
2012-04-14 01:06:11 +02:00
|
|
|
|
2012-08-14 01:17:14 +02:00
|
|
|
def load_config_file():
|
|
|
|
p = ConfigParser.ConfigParser()
|
2012-09-28 18:21:56 +02:00
|
|
|
path1 = os.path.expanduser(os.environ.get('ANSIBLE_CONFIG', "~/.ansible.cfg"))
|
|
|
|
path2 = os.getcwd() + "/ansible.cfg"
|
2012-09-10 16:57:32 +02:00
|
|
|
path3 = "/etc/ansible/ansible.cfg"
|
|
|
|
|
2012-08-14 01:17:14 +02:00
|
|
|
if os.path.exists(path1):
|
|
|
|
p.read(path1)
|
|
|
|
elif os.path.exists(path2):
|
|
|
|
p.read(path2)
|
2012-09-10 16:57:32 +02:00
|
|
|
elif os.path.exists(path3):
|
|
|
|
p.read(path3)
|
2012-08-14 01:17:14 +02:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
return p
|
|
|
|
|
2012-08-14 12:22:47 +02:00
|
|
|
def shell_expand_path(path):
|
2012-09-28 18:21:56 +02:00
|
|
|
''' shell_expand_path is needed as os.path.expanduser does not work
|
2012-08-14 12:22:47 +02:00
|
|
|
when path is None, which is the default for ANSIBLE_PRIVATE_KEY_FILE '''
|
|
|
|
if path:
|
|
|
|
path = os.path.expanduser(path)
|
|
|
|
return path
|
|
|
|
|
2012-08-14 01:17:14 +02:00
|
|
|
p = load_config_file()
|
|
|
|
|
|
|
|
active_user = pwd.getpwuid(os.geteuid())[0]
|
|
|
|
|
2012-10-11 19:22:30 +02:00
|
|
|
# Needed so the RPM can call setup.py and have modules land in the
|
|
|
|
# correct location. See #1277 for discussion
|
|
|
|
DIST_MODULE_PATH = '/usr/share/ansible/'
|
|
|
|
|
2012-08-14 01:17:14 +02:00
|
|
|
# sections in config file
|
|
|
|
DEFAULTS='defaults'
|
|
|
|
|
|
|
|
# configurable things
|
2012-08-14 12:22:47 +02:00
|
|
|
DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
|
2012-10-11 19:22:30 +02:00
|
|
|
DEFAULT_MODULE_PATH = shell_expand_path(get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH))
|
2012-08-14 12:22:47 +02:00
|
|
|
DEFAULT_REMOTE_TMP = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp'))
|
2012-08-14 01:17:14 +02:00
|
|
|
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')
|
|
|
|
DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, '*')
|
2012-08-14 12:22:47 +02:00
|
|
|
DEFAULT_FORKS = get_config(p, DEFAULTS, 'forks', 'ANSIBLE_FORKS', 5)
|
2012-08-14 01:17:14 +02:00
|
|
|
DEFAULT_MODULE_ARGS = get_config(p, DEFAULTS, 'module_args', 'ANSIBLE_MODULE_ARGS', '')
|
|
|
|
DEFAULT_TIMEOUT = get_config(p, DEFAULTS, 'timeout', 'ANSIBLE_TIMEOUT', 10)
|
|
|
|
DEFAULT_POLL_INTERVAL = get_config(p, DEFAULTS, 'poll_interval', 'ANSIBLE_POLL_INTERVAL', 15)
|
|
|
|
DEFAULT_REMOTE_USER = get_config(p, DEFAULTS, 'remote_user', 'ANSIBLE_REMOTE_USER', active_user)
|
2012-08-14 12:22:47 +02:00
|
|
|
DEFAULT_PRIVATE_KEY_FILE = shell_expand_path(get_config(p, DEFAULTS, 'private_key_file', 'ANSIBLE_PRIVATE_KEY_FILE', None))
|
2012-08-14 01:17:14 +02:00
|
|
|
DEFAULT_SUDO_USER = get_config(p, DEFAULTS, 'sudo_user', 'ANSIBLE_SUDO_USER', 'root')
|
2012-08-14 12:22:47 +02:00
|
|
|
DEFAULT_REMOTE_PORT = int(get_config(p, DEFAULTS, 'remote_port', 'ANSIBLE_REMOTE_PORT', 22))
|
2012-08-14 01:17:14 +02:00
|
|
|
DEFAULT_TRANSPORT = get_config(p, DEFAULTS, 'transport', 'ANSIBLE_TRANSPORT', 'paramiko')
|
2012-10-03 15:59:38 +02:00
|
|
|
DEFAULT_MANAGED_STR = get_config(p, DEFAULTS, 'ansible_managed', None, 'Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}')
|
2012-08-14 01:17:14 +02:00
|
|
|
|
2012-09-18 14:41:27 +02:00
|
|
|
DEFAULT_ACTION_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'action_plugins', None, '/usr/share/ansible_plugins/action_plugins'))
|
|
|
|
DEFAULT_CALLBACK_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'callback_plugins', None, '/usr/share/ansible_plugins/callback_plugins'))
|
|
|
|
DEFAULT_CONNECTION_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'connection_plugins', None, '/usr/share/ansible_plugins/connection_plugins'))
|
|
|
|
DEFAULT_LOOKUP_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'lookup_plugins', None, '/usr/share/ansible_plugins/lookup_plugins'))
|
2012-10-27 01:55:59 +02:00
|
|
|
DEFAULT_VARS_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'vars_plugins', None, '/usr/share/ansible_plugins/vars_plugins'))
|
2012-09-18 14:41:27 +02:00
|
|
|
|
2012-08-14 01:17:14 +02:00
|
|
|
# non-configurable things
|
|
|
|
DEFAULT_REMOTE_PASS = None
|
|
|
|
DEFAULT_SUDO_PASS = None
|
|
|
|
DEFAULT_SUBSET = None
|
|
|
|
|
2012-08-15 02:13:02 +02:00
|
|
|
ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None)
|
2012-09-27 05:50:54 +02:00
|
|
|
ZEROMQ_PORT = int(get_config(p, 'fireball', 'zeromq_port', 'ANSIBLE_ZEROMQ_PORT', 5099))
|