状态文件中的函数和saltstack中命令行中的函数有什么区别? [英] what's the differences between functions in state file and functions in command line in saltstack?

查看:22
本文介绍了状态文件中的函数和saltstack中命令行中的函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 saltstack 来管理我的服务器时.我发现了一个有趣的事情:当我运行 salt '*' pkg.installed httpd 时,我收到以下消息:pkg.installed is not available.但是我可以在我的 .sls 文件中使用 pkg.installed 函数并且它运行得非常好.所以,我对此感到困惑.我认为这是因为 saltstack.

When I use saltstack to manage my servers. I found an interesting thing: When I run salt '*' pkg.installed httpd, I get the following message: pkg.installed is not available. But I can use pkg.installed function in my .sls files and it worked very well. So, I am confused about that. And I think this is happening because of saltstack.

谁能帮帮我?

推荐答案

这里有两个相关但不同的概念.

There are two related but different concepts here.

  1. Salt 执行模块
  2. 盐态模块.

执行模块是大部分工作实际发生的地方,通常是您在命令行上运行的模块.例如:

Execution modules are where most of the work actually happens and is what you are running on the command line, generally. For example:

salt '*' pkg.install vim

这将直接调用您操作系统的包管理器,例如 yum 或 apt,并安装 vim.

That will call out directly to your OS's package manager, such as yum or apt, and install vim.

状态模块是有状态的命令,位于执行模块的上方".状态模块将检查所需的结果是否已经存在,并进行任何必要的更改以获得所需的状态.它们与执行模块的共轭方式不同.例如在这个 salt 状态文件(sls 文件)中:

State modules are statefull commands that kind of sit "above" the execution modules. A state module will check if the desired result already exists and make any necessary changes to get the desired state. They are conjugated differently than the execution modules. For example in this salt state file (sls file):

cat /srv/salt/vim.sls

install_vim_please:
  pkg.installed:
    - name: vim

然后你可以运行 state.sls 执行模块来应用这个具有 pkg.installed 状态的 sls 文件.

Then you could run the state.sls execution module to apply this sls file with the pkg.installed state.

salt '*' state.sls vim

因为我们使用的是 pkg.installed 状态,Salt 将检查您操作系统的包管理器并查看是否已经安装了 vim.如果包管理器说 vim 尚未安装,Salt 只会尝试安装 vim.

Because we're using the pkg.installed state Salt will check with your OS's package manager and see if vim is already installed. Salt will only attempt to install vim if the package manager says that vim is not installed already.

将您的 Salt 状态保存在 sls 文件中,可以轻松地将它们保存在 git 或用于跟踪它们的任何 vcs 中.

Keeping your Salt States in sls files makes it easy to keep them in git or whatever vcs you use to track them.

您可以跳过 sls 文件并像这样从命令行有状态地运行命令:

You could skip the sls file and run the command statefully from the command line like this:

salt '*' state.single pkg.installed name=vim

这篇关于状态文件中的函数和saltstack中命令行中的函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆