@ -23,7 +23,8 @@ from ansible.utils.path import unfrackpath
from ansible . utils . path import makedirs_safe
from ansible . utils . path import makedirs_safe
Plugin = namedtuple ( ' Plugin ' , ' name type ' )
Plugin = namedtuple ( ' Plugin ' , ' name type ' )
Setting = namedtuple ( ' Setting ' , ' name value origin ' )
Setting = namedtuple ( ' Setting ' , ' name value origin type ' )
# FIXME: see if we can unify in module_utils with similar function used by argspec
# FIXME: see if we can unify in module_utils with similar function used by argspec
def ensure_type ( value , value_type ) :
def ensure_type ( value , value_type ) :
@ -74,9 +75,15 @@ def ensure_type(value, value_type):
prefix = ' ansible-local- %s ' % os . getpid ( )
prefix = ' ansible-local- %s ' % os . getpid ( )
value = tempfile . mkdtemp ( prefix = prefix , dir = value )
value = tempfile . mkdtemp ( prefix = prefix , dir = value )
elif value_type == ' pathspec ' :
if isinstance ( value , string_types ) :
value = value . split ( os . pathsep )
value = [ resolve_path ( x ) for x in value ]
elif value_type == ' pathlist ' :
elif value_type == ' pathlist ' :
if isinstance ( value , string_types ) :
if isinstance ( value , string_types ) :
value = [ resolve_path ( x ) for x in value . split ( os . pathsep ) ]
value = value . split ( ' , ' )
value = [ resolve_path ( x ) for x in value ]
# defaults to string types
# defaults to string types
elif isinstance ( value , string_types ) :
elif isinstance ( value , string_types ) :
@ -84,6 +91,7 @@ def ensure_type(value, value_type):
return to_text ( value , errors = ' surrogate_or_strict ' , nonstring = ' passthru ' )
return to_text ( value , errors = ' surrogate_or_strict ' , nonstring = ' passthru ' )
# FIXME: see if this can live in utils/path
# FIXME: see if this can live in utils/path
def resolve_path ( path ) :
def resolve_path ( path ) :
''' resolve relative or ' varaible ' paths '''
''' resolve relative or ' varaible ' paths '''
@ -92,6 +100,7 @@ def resolve_path(path):
return unfrackpath ( path , follow = False )
return unfrackpath ( path , follow = False )
# FIXME: generic file type?
# FIXME: generic file type?
def get_config_type ( cfile ) :
def get_config_type ( cfile ) :
@ -107,6 +116,7 @@ def get_config_type(cfile):
return ftype
return ftype
# FIXME: can move to module_utils for use for ini plugins also?
# FIXME: can move to module_utils for use for ini plugins also?
def get_ini_config_value ( p , entry ) :
def get_ini_config_value ( p , entry ) :
''' returns the value of last ini entry found '''
''' returns the value of last ini entry found '''
@ -118,6 +128,7 @@ def get_ini_config_value(p, entry):
pass
pass
return value
return value
def find_ini_config_file ( ) :
def find_ini_config_file ( ) :
''' Load INI Config File order(first found is used): ENV, CWD, HOME, /etc/ansible '''
''' Load INI Config File order(first found is used): ENV, CWD, HOME, /etc/ansible '''
# FIXME: eventually deprecate ini configs
# FIXME: eventually deprecate ini configs
@ -142,6 +153,7 @@ def find_ini_config_file():
return path
return path
class ConfigManager ( object ) :
class ConfigManager ( object ) :
UNABLE = [ ]
UNABLE = [ ]
@ -156,7 +168,6 @@ class ConfigManager(object):
self . _config_file = conf_file
self . _config_file = conf_file
self . data = ConfigData ( )
self . data = ConfigData ( )
# FIXME: make dynamic? scan for more? make it's own method?
# FIXME: make dynamic? scan for more? make it's own method?
# Create configuration definitions from source
# Create configuration definitions from source
bconfig_def = to_bytes ( ' %s /base.yml ' % os . path . dirname ( __file__ ) )
bconfig_def = to_bytes ( ' %s /base.yml ' % os . path . dirname ( __file__ ) )
@ -200,12 +211,10 @@ class ConfigManager(object):
else :
else :
raise AnsibleOptionsError ( " Unsupported configuration file type: %s " % to_native ( ftype ) )
raise AnsibleOptionsError ( " Unsupported configuration file type: %s " % to_native ( ftype ) )
def _find_yaml_config_files ( self ) :
def _find_yaml_config_files ( self ) :
''' 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 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 '''
@ -232,7 +241,8 @@ class ConfigManager(object):
origin = name
origin = name
# deal with deprecation of setting source, if used
# deal with deprecation of setting source, if used
#FIXME: if entry.get('deprecated'):
if ' deprecated ' in entry :
self . DEPRECATED . append ( ( entry [ ' name ' ] , entry [ ' deprecated ' ] ) )
return value , origin
return value , origin
@ -277,7 +287,8 @@ class ConfigManager(object):
for ini_entry in defs [ config ] [ ' ini ' ] :
for ini_entry in defs [ config ] [ ' ini ' ] :
value = get_ini_config_value ( self . _parser , ini_entry )
value = get_ini_config_value ( self . _parser , ini_entry )
origin = cfile
origin = cfile
#FIXME: if ini_entry.get('deprecated'):
if ' deprecated ' in ini_entry :
self . DEPRECATED . append ( ( ' [ %s ] %s ' % ( ini_entry [ ' section ' ] , ini_entry [ ' key ' ] ) , ini_entry [ ' deprecated ' ] ) )
except Exception as e :
except Exception as e :
sys . stderr . write ( " Error while loading ini config %s : %s " % ( cfile , to_native ( e ) ) )
sys . stderr . write ( " Error while loading ini config %s : %s " % ( cfile , to_native ( e ) ) )
elif ftype == ' yaml ' :
elif ftype == ' yaml ' :
@ -315,17 +326,11 @@ class ConfigManager(object):
self . UNABLE . append ( config )
self . UNABLE . append ( config )
# deal with deprecation of the setting
# deal with deprecation of the setting
if defs [ config ] . get ( ' deprecated ' ) and origin != ' default ' :
if ' deprecated ' in defs [ config ] and origin != ' default ' :
self . DEPRECATED . append ( ( config , defs [ config ] . get ( ' deprecated ' ) ) )
self . DEPRECATED . append ( ( config , defs [ config ] . get ( ' deprecated ' ) ) )
return value , origin
return value , origin
def update_plugin_config ( self , plugin_type , name , defs ) :
''' really: update constants '''
# no sense?
self . initialize_plugin_configuration_definitions ( plugin_type , name , defs )
self . update_config_data ( defs )
def initialize_plugin_configuration_definitions ( self , plugin_type , name , defs ) :
def initialize_plugin_configuration_definitions ( self , plugin_type , name , defs ) :
if plugin_type not in self . _plugins :
if plugin_type not in self . _plugins :
@ -346,7 +351,7 @@ class ConfigManager(object):
raise AnsibleOptionsError ( " Invalid configuration definition type: %s for %s " % ( type ( defs ) , defs ) )
raise AnsibleOptionsError ( " Invalid configuration definition type: %s for %s " % ( type ( defs ) , defs ) )
# update the constant for config file
# update the constant for config file
self . data . update_setting ( Setting ( ' CONFIG_FILE ' , configfile , ' ' ))
self . data . update_setting ( Setting ( ' CONFIG_FILE ' , configfile , ' ' , ' string ' ))
origin = None
origin = None
# env and config defs can have several entries, ordered in list from lowest to highest precedence
# env and config defs can have several entries, ordered in list from lowest to highest precedence
@ -358,7 +363,7 @@ class ConfigManager(object):
value , origin = self . get_config_value_and_origin ( config , configfile )
value , origin = self . get_config_value_and_origin ( config , configfile )
# set the constant
# set the constant
self . data . update_setting ( Setting ( config , value , origin ))
self . data . update_setting ( Setting ( config , value , origin , defs [ config ] . get ( ' type ' , ' string ' ) ))
# FIXME: find better way to do this by passing back to where display is available
# FIXME: find better way to do this by passing back to where display is available
if self . UNABLE :
if self . UNABLE :