mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
commit
4713574a01
4
.gitignore
vendored
4
.gitignore
vendored
@ -64,3 +64,7 @@ _version.py
|
|||||||
|
|
||||||
# Ignore grains file written out during tests
|
# Ignore grains file written out during tests
|
||||||
tests/integration/files/conf/grains
|
tests/integration/files/conf/grains
|
||||||
|
/salt/_syspaths.py
|
||||||
|
|
||||||
|
# ignore the local root
|
||||||
|
/root/**
|
||||||
|
@ -26,6 +26,17 @@
|
|||||||
|
|
||||||
The \texttt{top.sls} file is used to map what SLS modules get loaded onto what minions via the state system.\\
|
The \texttt{top.sls} file is used to map what SLS modules get loaded onto what minions via the state system.\\
|
||||||
|
|
||||||
|
It is located in the file defined in the \texttt{file_roots} variable of the
|
||||||
|
salt master configuration file which is found in
|
||||||
|
\texttt{CONFIG_DIR}/master.
|
||||||
|
|
||||||
|
The file roots is defined like this by default.
|
||||||
|
\begin{verbatim}
|
||||||
|
file_roots:
|
||||||
|
base:
|
||||||
|
- /srv/salt
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
Here is an example \texttt{top.sls} file which uses \texttt{pkg}, \texttt{file} and \texttt{service} states:
|
Here is an example \texttt{top.sls} file which uses \texttt{pkg}, \texttt{file} and \texttt{service} states:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
|
@ -67,6 +67,9 @@ States - Configuration Management with Salt:
|
|||||||
Masterless Quickstart:
|
Masterless Quickstart:
|
||||||
:doc:`Salt Quickstart </topics/tutorials/quickstart>`
|
:doc:`Salt Quickstart </topics/tutorials/quickstart>`
|
||||||
|
|
||||||
|
Running Salt without root access in userland:
|
||||||
|
- :doc:`Salt Usermode <topics/tutorials/rooted.rst>`
|
||||||
|
|
||||||
A list of all tutorials can be found here:
|
A list of all tutorials can be found here:
|
||||||
:doc:`All Salt tutorials <topics/tutorials/index>`
|
:doc:`All Salt tutorials <topics/tutorials/index>`
|
||||||
|
|
||||||
@ -288,4 +291,4 @@ More information about the project
|
|||||||
The SaltStack security disclosure policy
|
The SaltStack security disclosure policy
|
||||||
|
|
||||||
.. _`salt-contrib`: https://github.com/saltstack/salt-contrib
|
.. _`salt-contrib`: https://github.com/saltstack/salt-contrib
|
||||||
.. _`salt-states`: https://github.com/saltstack/salt-states
|
.. _`salt-states`: https://github.com/saltstack/salt-states
|
||||||
|
@ -247,3 +247,30 @@ service.
|
|||||||
auth_timeout:
|
auth_timeout:
|
||||||
The total time to wait for the authentication process to complete, regardless
|
The total time to wait for the authentication process to complete, regardless
|
||||||
of the number of attempts.
|
of the number of attempts.
|
||||||
|
|
||||||
|
|
||||||
|
=====================
|
||||||
|
Running state locally
|
||||||
|
=====================
|
||||||
|
|
||||||
|
To debug the states, you can use call locally.
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
salt-call -l trace --local state.highstate
|
||||||
|
|
||||||
|
|
||||||
|
The top.sls file is used to map what SLS modules get loaded onto what minions via the state system.
|
||||||
|
|
||||||
|
It is located in the file defined in the ``file_roots`` variable of the salt master
|
||||||
|
configuration file which is defined by found in ``CONFIG_DIR/master``, normally ``/etc/salt/master``
|
||||||
|
|
||||||
|
The default configuration for the ``file_roots`` is:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
file_roots:
|
||||||
|
base:
|
||||||
|
- /srv/salt
|
||||||
|
|
||||||
|
So the top file is defaulted to the location ``/srv/salt/top.sls``
|
||||||
|
80
doc/topics/tutorials/rooted.rst
Normal file
80
doc/topics/tutorials/rooted.rst
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
====================================
|
||||||
|
running salt as normal user tutorial
|
||||||
|
====================================
|
||||||
|
|
||||||
|
.. include:: /_incl/requisite_incl.rst
|
||||||
|
|
||||||
|
Running Salt functions as non root user
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
If you dont want to run salt cloud as root or even install it you can
|
||||||
|
configure it to have a virtual root in your working directory.
|
||||||
|
|
||||||
|
The salt system uses the ``salt.syspath`` module to find the variables
|
||||||
|
|
||||||
|
If you run the salt-build, it will generated in:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
./build/lib.linux-x86_64-2.7/salt/_syspaths.py
|
||||||
|
|
||||||
|
To generate it, run the command:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
python setup.py build
|
||||||
|
|
||||||
|
Copy the generated module into your salt directory
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
cp ./build/lib.linux-x86_64-2.7/salt/_syspaths.py salt/_syspaths.py
|
||||||
|
|
||||||
|
Edit it to include needed variables and your new paths
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# you need to edit this
|
||||||
|
ROOT_DIR = *your current dir* + '/salt/root'
|
||||||
|
|
||||||
|
# you need to edit this
|
||||||
|
INSTALL_DIR = *location of source code*
|
||||||
|
|
||||||
|
CONFIG_DIR = ROOT_DIR + '/etc/salt'
|
||||||
|
CACHE_DIR = ROOT_DIR + '/var/cache/salt'
|
||||||
|
SOCK_DIR = ROOT_DIR + '/var/run/salt'
|
||||||
|
SRV_ROOT_DIR= ROOT_DIR + '/srv'
|
||||||
|
BASE_FILE_ROOTS_DIR = ROOT_DIR + '/srv/salt'
|
||||||
|
BASE_PILLAR_ROOTS_DIR = ROOT_DIR + '/srv/pillar'
|
||||||
|
BASE_MASTER_ROOTS_DIR = ROOT_DIR + '/srv/salt-master'
|
||||||
|
LOGS_DIR = ROOT_DIR + '/var/log/salt'
|
||||||
|
PIDFILE_DIR = ROOT_DIR + '/var/run'
|
||||||
|
CLOUD_DIR = INSTALL_DIR + '/cloud'
|
||||||
|
BOOTSTRAP = CLOUD_DIR + '/deploy/bootstrap-salt.sh'
|
||||||
|
|
||||||
|
|
||||||
|
Create the directory structure
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
mkdir -p root/etc/salt root/var/cache/run root/run/salt root/srv
|
||||||
|
root/srv/salt root/srv/pillar root/srv/salt-master root/var/log/salt root/var/run
|
||||||
|
|
||||||
|
|
||||||
|
Populate the configuration files:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
cp -r conf/* root/etc/salt/
|
||||||
|
|
||||||
|
Edit your ``root/etc/salt/master`` configuration that is used by salt-cloud:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
user: *your user name*
|
||||||
|
|
||||||
|
Run like this:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
PYTHONPATH=`pwd` scripts/salt-cloud
|
@ -1,13 +1,25 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import print_function
|
'''
|
||||||
from __future__ import absolute_import
|
salt.cli.api
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
import salt.ext.six as six
|
Salt's api cli parser.
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Import Python libs
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
import sys
|
import sys
|
||||||
|
import os.path
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
# Import Salt libs
|
||||||
import salt.utils.parsers as parsers
|
import salt.utils.parsers as parsers
|
||||||
import salt.version
|
import salt.version
|
||||||
|
import salt.syspaths as syspaths
|
||||||
|
|
||||||
|
# Import 3rd-party libs
|
||||||
|
import salt.ext.six as six
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -25,7 +37,7 @@ class SaltAPI(six.with_metaclass(parsers.OptionParserMeta, # pylint: disable=W0
|
|||||||
# ConfigDirMixIn config filename attribute
|
# ConfigDirMixIn config filename attribute
|
||||||
_config_filename_ = 'master'
|
_config_filename_ = 'master'
|
||||||
# LogLevelMixIn attributes
|
# LogLevelMixIn attributes
|
||||||
_default_logging_logfile_ = '/var/log/salt/api'
|
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'api')
|
||||||
|
|
||||||
def setup_config(self):
|
def setup_config(self):
|
||||||
return salt.config.api_config(self.get_config_file_path())
|
return salt.config.api_config(self.get_config_file_path())
|
||||||
|
@ -4,9 +4,9 @@ Primary interfaces for the salt-cloud system
|
|||||||
'''
|
'''
|
||||||
# Need to get data from 4 sources!
|
# Need to get data from 4 sources!
|
||||||
# CLI options
|
# CLI options
|
||||||
# salt cloud config - /etc/salt/cloud
|
# salt cloud config - CONFIG_DIR + '/cloud'
|
||||||
# salt master config (for master integration)
|
# salt master config (for master integration)
|
||||||
# salt VM config, where VMs are defined - /etc/salt/cloud.profiles
|
# salt VM config, where VMs are defined - CONFIG_DIR + '/cloud.profiles'
|
||||||
#
|
#
|
||||||
# The cli, master and cloud configs will merge for opts
|
# The cli, master and cloud configs will merge for opts
|
||||||
# the VM data will be in opts['profiles']
|
# the VM data will be in opts['profiles']
|
||||||
@ -31,7 +31,7 @@ from salt.utils.verify import check_user, verify_env, verify_files
|
|||||||
import salt.cloud
|
import salt.cloud
|
||||||
from salt.exceptions import SaltCloudException, SaltCloudSystemExit
|
from salt.exceptions import SaltCloudException, SaltCloudSystemExit
|
||||||
import salt.ext.six as six
|
import salt.ext.six as six
|
||||||
|
import salt.syspaths as syspaths
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -50,9 +50,10 @@ class SaltCloud(parsers.SaltCloudParser):
|
|||||||
'If salt-cloud is running on a master machine, salt-cloud '
|
'If salt-cloud is running on a master machine, salt-cloud '
|
||||||
'needs to run as the same user as the salt-master, {0!r}. If '
|
'needs to run as the same user as the salt-master, {0!r}. If '
|
||||||
'salt-cloud is not running on a salt-master, the appropriate '
|
'salt-cloud is not running on a salt-master, the appropriate '
|
||||||
'write permissions must be granted to /etc/salt/. Please run '
|
'write permissions must be granted to {1!r}. Please run '
|
||||||
'salt-cloud as root, {0!r}, or change permissions for '
|
'salt-cloud as root, {0!r}, or change permissions for '
|
||||||
'/etc/salt/.'.format(salt_master_user)
|
'{1!r}.'.format(salt_master_user,
|
||||||
|
syspaths.CONFIG_DIR)
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -302,7 +302,8 @@ def salt_cloud():
|
|||||||
try:
|
try:
|
||||||
import salt.cloud.cli
|
import salt.cloud.cli
|
||||||
has_saltcloud = True
|
has_saltcloud = True
|
||||||
except ImportError:
|
except ImportError as e:
|
||||||
|
log.error("Error importing salt cloud {0}".format(e))
|
||||||
# No salt cloud on Windows
|
# No salt cloud on Windows
|
||||||
has_saltcloud = False
|
has_saltcloud = False
|
||||||
if '' in sys.path:
|
if '' in sys.path:
|
||||||
|
@ -21,13 +21,19 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
if 'SETUP_DIRNAME' in globals():
|
if 'SETUP_DIRNAME' in globals():
|
||||||
# This is from the exec() call in Salt's setup.py
|
# This is from the exec() call in Salt's setup.py
|
||||||
THIS_FILE = os.path.join(SETUP_DIRNAME, 'salt', 'syspaths.py') # pylint: disable=E0602
|
THIS_FILE = os.path.join(SETUP_DIRNAME, 'salt', 'syspaths.py') # pylint: disable=E0602
|
||||||
else:
|
else:
|
||||||
THIS_FILE = __file__
|
THIS_FILE = __file__
|
||||||
|
|
||||||
|
# These defaults won't changes and are not to be overridden
|
||||||
|
INSTALL_DIR = os.path.dirname(os.path.realpath(THIS_FILE))
|
||||||
|
CLOUD_DIR = os.path.join(INSTALL_DIR, 'cloud')
|
||||||
|
BOOTSTRAP = os.path.join(CLOUD_DIR, 'deploy', 'bootstrap-salt.sh')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Let's try loading the system paths from the generated module at
|
# Let's try loading the system paths from the generated module at
|
||||||
# installation time.
|
# installation time.
|
||||||
@ -42,11 +48,9 @@ try:
|
|||||||
BASE_MASTER_ROOTS_DIR,
|
BASE_MASTER_ROOTS_DIR,
|
||||||
LOGS_DIR,
|
LOGS_DIR,
|
||||||
PIDFILE_DIR,
|
PIDFILE_DIR,
|
||||||
CLOUD_DIR,
|
|
||||||
INSTALL_DIR,
|
|
||||||
BOOTSTRAP,
|
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError as error:
|
||||||
|
log.error('Error importing salt._syspaths with exception {0}'.format(error))
|
||||||
# The installation time was not generated, let's define the default values
|
# The installation time was not generated, let's define the default values
|
||||||
__platform = sys.platform.lower()
|
__platform = sys.platform.lower()
|
||||||
if __platform.startswith('win'):
|
if __platform.startswith('win'):
|
||||||
@ -68,6 +72,3 @@ except ImportError:
|
|||||||
BASE_MASTER_ROOTS_DIR = os.path.join(SRV_ROOT_DIR, 'salt-master')
|
BASE_MASTER_ROOTS_DIR = os.path.join(SRV_ROOT_DIR, 'salt-master')
|
||||||
LOGS_DIR = os.path.join(ROOT_DIR, 'var', 'log', 'salt')
|
LOGS_DIR = os.path.join(ROOT_DIR, 'var', 'log', 'salt')
|
||||||
PIDFILE_DIR = os.path.join(ROOT_DIR, 'var', 'run')
|
PIDFILE_DIR = os.path.join(ROOT_DIR, 'var', 'run')
|
||||||
INSTALL_DIR = os.path.dirname(os.path.realpath(THIS_FILE))
|
|
||||||
CLOUD_DIR = os.path.join(INSTALL_DIR, 'cloud')
|
|
||||||
BOOTSTRAP = os.path.join(CLOUD_DIR, 'deploy', 'bootstrap-salt.sh')
|
|
||||||
|
@ -9,10 +9,8 @@
|
|||||||
This is where all the black magic happens on all of salt's CLI tools.
|
This is where all the black magic happens on all of salt's CLI tools.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
# Import python libs
|
# Import python libs
|
||||||
from __future__ import print_function
|
from __future__ import absolute_import, print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import getpass
|
import getpass
|
||||||
@ -410,6 +408,7 @@ class ConfigDirMixIn(object):
|
|||||||
config_dir = os.environ.get('SALT_CONFIG_DIR', None)
|
config_dir = os.environ.get('SALT_CONFIG_DIR', None)
|
||||||
if not config_dir:
|
if not config_dir:
|
||||||
config_dir = syspaths.CONFIG_DIR
|
config_dir = syspaths.CONFIG_DIR
|
||||||
|
logging.getLogger(__name__).debug('SYSPATHS setup as: {0}'.format(syspaths.CONFIG_DIR))
|
||||||
self.add_option(
|
self.add_option(
|
||||||
'-c', '--config-dir', default=config_dir,
|
'-c', '--config-dir', default=config_dir,
|
||||||
help=('Pass in an alternative configuration directory. Default: '
|
help=('Pass in an alternative configuration directory. Default: '
|
||||||
@ -420,7 +419,7 @@ class ConfigDirMixIn(object):
|
|||||||
if not os.path.isdir(self.options.config_dir):
|
if not os.path.isdir(self.options.config_dir):
|
||||||
# No logging is configured yet
|
# No logging is configured yet
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
'WARNING: {0!r} directory does not exist.\n'.format(
|
'WARNING: CONFIG {0!r} directory does not exist.\n'.format(
|
||||||
self.options.config_dir
|
self.options.config_dir
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user