在Saltstack中,我有以下用例:
有一个状态redis.sls可以包含在其他州.redis.sls的结果应该以不同的方式配置,具体取决于包含redis.sls的状态.
例如:
redis.sls:
--------
{% if x==1 %}
#do something
{% else %}
#do something else
{% endif %}
state_a.sls
-----------
{% set x=1 %}
include:
- redis
state_b.sls
-----------
{% set x=2 %}
include:
- redis
Run Code Online (Sandbox Code Playgroud)
但*在*state_a*和*state_b*中无法识别x
我也尝试用这样的东西设置支柱值:
{{salt['pillar.set']('x', 1)}}
Run Code Online (Sandbox Code Playgroud)
但那也不起作用.
还有其他想法吗?
我们如何构建salt状态树,以便能够highstate在主机上运行的大量运行中运行一个virtualenv?
我们使用面料为开发和生产运行virtualenvs.我们想从面料换成盐.一切都很好,除了highstate需要太长时间.我们在一个主机上有100多个virtualenvs,并且caling highstate将更新100+ virtualenvs.
如果我必须执行以下3个命令,我该如何对它们进行分组,所以我只需要调用一个命令?
salt '*' git.fetch cwd=/var/git/myproject opts='--all' user=git
salt '*' git.pull cwd=/var/git/myproject opts='origin master'
salt '*' nginx.signal reload
Run Code Online (Sandbox Code Playgroud)
我可以使用面料把它们放在一个函数中说deploy可能接受一个minion名称然后通过master运行,但是我想知道saltstack是否有内置的东西?
如何使用sls文件中的必备项使一个自定义状态依赖于另一个自定义状态?
例如: 两个自定义状态一个在_states/seuss.py模块:
# seuss.py
def green_eggs():
return {'name': 'green_eggs', 'result': True, 'comment': '', 'changes': {}}
def ham():
return {'name': 'ham', 'result': True, 'comment': '', 'changes': {}}
Run Code Online (Sandbox Code Playgroud)
我想要ham依赖green_eggs:
# init.sls
have_green_eggs:
seuss.green_eggs:
- require:
- user: seuss
have_ham:
seuss.ham:
- require:
- ???
Run Code Online (Sandbox Code Playgroud)
如何???依赖成功完成green_eggs?
当使用cloud init 的#cloud-config 创建配置文件时,我将如何使用变量来填充值?
在我的特定情况下,我想自动启动 EC2 实例作为预配置的 salt minions。salt minion 云配置示例
假设我想获取特定的 EC2 实例 ID 并将其设置为 salt minion 的 ID。
我将如何为每个实例动态设置值?
我是盐堆的新手.
我正在努力确保存在符号链接.
/etc/localtime:
file.symlink:
- target: /usr/share/zoneinfo/Europe/Paris
- file.exists:
- name: /usr/share/zoneinfo/Europe/Paris
Run Code Online (Sandbox Code Playgroud)
当没有存在/etc/localtime或者/etc/localtime已经是符号链接时,结果是例外.但它/etc/localtime是常规文件时失败:
----------
State: - file
Name: /etc/localtime
Function: symlink
Result: False
Comment: File exists where the symlink /etc/localtime should be
Changes:
Run Code Online (Sandbox Code Playgroud)
我无法想象如何编码状态,因此在创建链接之前删除文件.任何线索?
干杯,皮埃尔
这是我的目标文件:
Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=/opt/nexuswork
runtime=${bundleBasedir}/nexus/WEB-INF
Run Code Online (Sandbox Code Playgroud)
我知道使用正则表达式或简单的sed脚本有一种简单的方法:
sed -i 's/${bundleBasedir}\/..\/my\/second\/path\/002\/\/nexus/\/myfirstdir001\/g'
Run Code Online (Sandbox Code Playgroud)
但是,理想情况下,我更喜欢盐栈方式.
我希望它看起来像这样:
Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=/my/second/path/002/nexus # changed
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=/opt/nexuswork
runtime=/myfirstdir001/nexus/WEB-INF # changed
Run Code Online (Sandbox Code Playgroud)
我还没有弄清楚这方面的saltstack文档.
Saltstack的salt.states.file.replace文档似乎相当简单:
http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.replace
这是我试过的:
/opt/nexus-2.8.0/conf/nexus.properties
file: # state
- replace
- pattern: '\$\{bundleBasedir\}' # without escapes: '${bundleBasedir}/nexus' …Run Code Online (Sandbox Code Playgroud) Jinja2(在 Saltstack 中支持)似乎不支持正则表达式匹配,除非我遗漏了什么?许多利用 Jinja2 的框架,例如Ansible,都有对正则表达式过滤器的自定义支持。 在其他地方,人们被指示编写自定义过滤器。
向知情人士提出的一些问题可能有助于理解这种情况:
我一直在寻找SaltStack文档中有关"上下文"含义的解释.但是只有使用上下文的例子.
什么是'背景'?
它在这做什么?为什么Debian在map.jinja文件中被忽略?(例如map.log_dir似乎"跳下"一个级别)
# config.sls
{% from "bind/map.jinja" import map with context %}
include:
- bind
{{ map.log_dir }}:
file.directory:
- user: root
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: 775
- require:
- pkg: bind
# map.jinja
{% set map = salt['grains.filter_by']({
'Debian': {
'pkgs': ['bind9', 'bind9utils', 'dnssec-tools'],
'service': 'bind9',
'config_source_dir': 'bind/files/debian',
'zones_source_dir': 'zones',
'config': '/etc/bind/named.conf',
'local_config': '/etc/bind/named.conf.local',
'key_config': '/etc/bind/named.conf.key',
'options_config': '/etc/bind/named.conf.options',
'default_config': '/etc/default/bind9',
'default_zones_config': '/etc/bind/named.conf.default-zones',
'named_directory': '/var/cache/bind/zones',
'log_dir': '/var/log/bind9',
'user': 'root', …Run Code Online (Sandbox Code Playgroud) 我是 SaltStack 的新手,并遵循了一些教程并尝试执行 state.apply 但出现以下错误:
Run Code Online (Sandbox Code Playgroud)# salt "host2" state.apply host2: ---------- ID: states Function: no.None Result: False Comment: No Top file or external nodes data matches found Started: Duration: Changes: Summary for host2 ------------ Succeeded: 0 Failed: 1 ------------ Total states run: 1
我能够通过 test.ping 成功托管。这是目录结构:
/etc/salt/srv/salt/states
|-top.sls
|-installations
|-init.sls
Run Code Online (Sandbox Code Playgroud)
主配置中的文件根条目
file_roots:
base:
- /srv/salt/states
Run Code Online (Sandbox Code Playgroud)
top.sls ->
base:
'*':
- installations
Run Code Online (Sandbox Code Playgroud)
init.sls->
install_apache:
pkg.installed:
- name: apache2
Run Code Online (Sandbox Code Playgroud) salt-stack ×10
python ×2
amazon-ec2 ×1
boto ×1
cloud-init ×1
devops ×1
jinja2 ×1
nexus ×1
regex ×1
replace ×1
virtualenv ×1