salt-stack - Salt: install package and run service (name different than package)
问题描述
Currently trying to wrap my head around Salt.
In essence I'd like to install a package (rpm) and enable and run the service (if the package installed successfully).
Surprise: The service is called differently than the package.
Let's say
- the package is called x
- but the (systemd/init) service this package installs is called y
This does not work
my_state_id:
pkg.installed:
- pkgs:
- x
service.running:
- name: y
- enable: true
- require:
- pkg: x
Result:
Comment: The following requisites were not found:
require:
pkg: x
It looks like I have to write it like this and reference the state and not the package:
my_state_id:
pkg.installed:
- pkgs:
- x
service.running:
- name: y
- enable: true
- require:
- pkg: my_state_id
But: What does require: pkg: my_state_id
mean? =D "if the state up to this point didn't fail, then run the current module"?
解决方案
引用必备文档:
必要目标的广义形式是
<state name>: <ID or name>
。
如果我们破坏了您的my_state_id
ID:
my_state_id
是身份证pkg
并且service
是州名pkg
state 没有name
参数,但service
state 有,而且是y
由于pkg
state 没有name
参数,我们需要使用它的 ID 来指定它:
- 在左侧,我们将有
pkg
- 在右侧它将是 ID
my_state_id
- require:
- pkg: my_state_id
另一种写法是:
# give the package name in 'name' parameter
my_state_id:
pkg.installed:
- name: x
service.running:
- name: y
- enable: true
- require:
- pkg: x
所以这是一种告诉 Saltstack 有条件地采取行动的方法。在这种情况下,如果包安装失败,那么它不应该尝试启动服务(并且失败)。
推荐阅读
- python - Python Pandas:在大型 DF 中找到局部最大值的最佳方法
- sql - 如何在标准 SQL (BigQuery) 中获取会话持续时间
- javascript - 如何直接在猫鼬的嵌套地图中设置值
- python - 如何从 python 脚本转发到 rds 实例
- sql-server - 如何动态读取多个存储过程的查询执行计划
- swiftui - SwiftUI:如何让搜索栏成为第一响应者?
- react-native - 如何在 react-native expo 中将资产库:// 转换为文件://?
- python - 有没有办法或例子用 ply 和 ast 创建抽象的 sytanx 树?
- android - 无法在颤振中创建捆绑包
- javascript - 使用 innerHTML 更改 Div 内容