plugins/actions/config_template.py
def _load_options_and_status(self, task_vars):
        """Return options and status from module load."""

        config_type = self._task.args.get('config_type')
        if config_type not in ['ini', 'yaml', 'json']:
            return False, dict(
                failed=True,
                msg="No valid [ config_type ] was provided. Valid options are"
                    " ini, yaml, or json."
            )

        # Access to protected method is unavoidable in Ansible
        searchpath = [self._loader._basedir]

        if self._task._role:
            file_path = self._task._role._role_path
            searchpath.insert(1, C.DEFAULT_ROLES_PATH)
            searchpath.insert(1, self._task._role._role_path)
        else:
            file_path = self._loader.get_basedir()

        user_source = self._task.args.get('src')
        # (alextricity25) It's possible that the user could pass in a datatype
        # and not always a string. In this case we don't want the datatype
        # python representation to be printed out to the file, but rather we
        # want the serialized version.
        _user_content = self._task.args.get('content')

        # If the data type of the content input is a dictionary, it's
        # converted dumped as json if config_type is 'json'.
        if isinstance(_user_content, dict):
            if self._task.args.get('config_type') == 'json':
                _user_content = json.dumps(_user_content)

        user_content = str(_user_content)
        if not user_source:
            if not user_content:
                return False, dict(
                    failed=True,
                    msg="No user [ src ] or [ content ] was provided"
                )
            else:
                tmp_content = None
                fd, tmp_content = tmpfilelib.mkstemp()
                try:
                    with open(tmp_content, 'wb') as f:
                        f.write(user_content.encode())
                except Exception as err:
                    os.remove(tmp_content)
                    raise Exception(err)
                self._task.args['src'] = source = tmp_content
        else:
            source = self._loader.path_dwim_relative(
                file_path,
                'templates',
                user_source
            )
        searchpath.insert(1, os.path.dirname(source))

        _dest = self._task.args.get('dest')
        list_extend = self._task.args.get('list_extend')
        if not _dest:
            return False, dict(
                failed=True,
                msg="No [ dest ] was provided"
            )
        else:
            # Expand any user home dir specification
            user_dest = self._remote_expand_user(_dest)
            if user_dest.endswith(os.sep):
                user_dest = os.path.join(user_dest, os.path.basename(source))

        # Get ignore_none_type
        # In some situations(i.e. my.cnf files), INI files can have valueless
        # options that don't have a '=' or ':' suffix. In these cases,
        # ConfigParser gives these options a "None" value. If ignore_none_type
        # is set to true, these key/value options will be ignored, if it's set
        # to false, then ConfigTemplateParser will write out only the option
        # name with out the '=' or ':' suffix. The default is true.
        ignore_none_type = self._task.args.get('ignore_none_type', True)

        default_section = self._task.args.get('default_section', 'DEFAULT')

        return True, dict(
            source=source,
            dest=user_dest,
            config_overrides=self._task.args.get('config_overrides', {}),
            config_type=config_type,
            searchpath=searchpath,
            list_extend=list_extend,
            ignore_none_type=ignore_none_type,
            default_section=default_section
        )
Return options and status from module load.
Return options and status from module load.
Return options and status from module load .
def _load_options_and_status(self, task_vars):
        config_type = self._task.args.get('config_type')
        if config_type not in ['ini', 'yaml', 'json']:
            return False, dict(
                failed=True,
                msg="No valid [ config_type ] was provided. Valid options are"
                    " ini, yaml, or json."
            )
        searchpath = [self._loader._basedir]
        if self._task._role:
            file_path = self._task._role._role_path
            searchpath.insert(1, C.DEFAULT_ROLES_PATH)
            searchpath.insert(1, self._task._role._role_path)
        else:
            file_path = self._loader.get_basedir()
        user_source = self._task.args.get('src')
        _user_content = self._task.args.get('content')
        if isinstance(_user_content, dict):
            if self._task.args.get('config_type') == 'json':
                _user_content = json.dumps(_user_content)
        user_content = str(_user_content)
        if not user_source:
            if not user_content:
                return False, dict(
                    failed=True,
                    msg="No user [ src ] or [ content ] was provided"
                )
            else:
                tmp_content = None
                fd, tmp_content = tmpfilelib.mkstemp()
                try:
                    with open(tmp_content, 'wb') as f:
                        f.write(user_content.encode())
                except Exception as err:
                    os.remove(tmp_content)
                    raise Exception(err)
                self._task.args['src'] = source = tmp_content
        else:
            source = self._loader.path_dwim_relative(
                file_path,
                'templates',
                user_source
            )
        searchpath.insert(1, os.path.dirname(source))
        _dest = self._task.args.get('dest')
        list_extend = self._task.args.get('list_extend')
        if not _dest:
            return False, dict(
                failed=True,
                msg="No [ dest ] was provided"
            )
        else:
            user_dest = self._remote_expand_user(_dest)
            if user_dest.endswith(os.sep):
                user_dest = os.path.join(user_dest, os.path.basename(source))
        ignore_none_type = self._task.args.get('ignore_none_type', True)
        default_section = self._task.args.get('default_section', 'DEFAULT')
        return True, dict(
            source=source,
            dest=user_dest,
            config_overrides=self._task.args.get('config_overrides', {}),
            config_type=config_type,
            searchpath=searchpath,
            list_extend=list_extend,
            ignore_none_type=ignore_none_type,
            default_section=default_section
        )
def _load_options_and_status ( self , task_vars ) : config_type = self . _task . args . get ( 'config_type' ) if config_type not in [ 'ini' , 'yaml' , 'json' ] : return False , dict ( failed = True , msg = "No valid [ config_type ] was provided. Valid options are" " ini, yaml, or json." ) searchpath = [ self . _loader . _basedir ] if self . _task . _role : file_path = self . _task . _role . _role_path searchpath . insert ( 1 , C . DEFAULT_ROLES_PATH ) searchpath . insert ( 1 , self . _task . _role . _role_path ) else : file_path = self . _loader . get_basedir ( ) user_source = self . _task . args . get ( 'src' ) _user_content = self . _task . args . get ( 'content' ) if isinstance ( _user_content , dict ) : if self . _task . args . get ( 'config_type' ) == 'json' : _user_content = json . dumps ( _user_content ) user_content = str ( _user_content ) if not user_source : if not user_content : return False , dict ( failed = True , msg = "No user [ src ] or [ content ] was provided" ) else : tmp_content = None fd , tmp_content = tmpfilelib . mkstemp ( ) try : with open ( tmp_content , 'wb' ) as f : f . write ( user_content . encode ( ) ) except Exception as err : os . remove ( tmp_content ) raise Exception ( err ) self . _task . args [ 'src' ] = source = tmp_content else : source = self . _loader . path_dwim_relative ( file_path , 'templates' , user_source ) searchpath . insert ( 1 , os . path . dirname ( source ) ) _dest = self . _task . args . get ( 'dest' ) list_extend = self . _task . args . get ( 'list_extend' ) if not _dest : return False , dict ( failed = True , msg = "No [ dest ] was provided" ) else : user_dest = self . _remote_expand_user ( _dest ) if user_dest . endswith ( os . sep ) : user_dest = os . path . join ( user_dest , os . path . basename ( source ) ) ignore_none_type = self . _task . args . get ( 'ignore_none_type' , True ) default_section = self . _task . args . get ( 'default_section' , 'DEFAULT' ) return True , dict ( source = source , dest = user_dest , config_overrides = self . _task . args . get ( 'config_overrides' , { } ) , config_type = config_type , searchpath = searchpath , list_extend = list_extend , ignore_none_type = ignore_none_type , default_section = default_section )
Return options and status from module load.
Return options and status from module load .
"""Return options and status from module load.""" # Access to protected method is unavoidable in Ansible # (alextricity25) It's possible that the user could pass in a datatype # and not always a string. In this case we don't want the datatype # python representation to be printed out to the file, but rather we # want the serialized version. # If the data type of the content input is a dictionary, it's # converted dumped as json if config_type is 'json'. # Expand any user home dir specification # Get ignore_none_type # In some situations(i.e. my.cnf files), INI files can have valueless # options that don't have a '=' or ':' suffix. In these cases, # ConfigParser gives these options a "None" value. If ignore_none_type # is set to true, these key/value options will be ignored, if it's set # to false, then ConfigTemplateParser will write out only the option # name with out the '=' or ':' suffix. The default is true.
self
task_vars