具有单个 top.sls 的 GitFS Salt 环境

具有单个 top.sls 的 GitFS Salt 环境

文档指出如果你使用

salt_top_saltenv: base

在主配置中,我可以强制所有 Minions 仅使用基本 saltenv 作为顶级文件,而忽略所有其他顶级文件,对吗?

将 state_top_saltenv 设置为 base 后,将应用基础顶级文件中所有环境的所有状态,同时忽略所有其他顶级文件

我正在尝试使用 Gitfs 作为后端,但得到了一些奇怪的结果 (state.show_top) 没有匹配任何内容。

我有以下配置

  • 单个 git 存储库
  • 4x 参考,基础,开发,分期,生产

我正在尝试为 top 文件实现单个引用(基础),然后实现每个环境的状态。然后我可以通过合并在环境中推动更改,并尝试尽可能保持 top.sls 的静态性。

##### Salt Master config #####

salt_top_saltenv: base
top_file_merging_strategy: same
gitfs_base: base

gitfs_saltenv:
  - base:
    - ref: base
  - development:
    - ref: development
  - staging:
    - ref: staging
  - production:
    - ref: production
gitfs_remotes:

  # Salt States
  - ssh://[email protected]/Salt.git:
    - name: salt
    - root: states
    - mountpoint: salt://


##### How the repo is laid out #####

# Base Branch

README.md
.gitignore
states/top.sls

# Development Branch

README.md
.gitignore
states/Test/init.sls

# Staging Branch

README.md
.gitignore
states/Test/init.sls

# Production Branch

README.md
.gitignore
states/Test/init.sls


##### Top.sls #####

{# The saltenv variable represents the environment the Minion is configured 
to #}
{{ saltenv }}:

  '*':

    # Apply states.test to everything from the matching env
    {%- do salt.log.info("Applying Salt states.test from" + saltenv + 
"environment" ) %}
- states.Test


##### Example Minion config ######

master: salt-master.mydomain.com
saltenv: development


From the Minion I am able to list the files on the Master correctly as 
expected

# Not specifying the saltenv results in the base being used
sudo salt '*' cp.list_master

top.sls

# Specifying the Base saltenv
sudo salt '*' cp.list_master saltenv=base

top.sls

# Specifying the Development saltenv
sudo salt '*' cp.list_master saltenv=development

Test/init.sls

当我尝试显示顶部匹配时,Salt 正在开发环境中查找,而不是像我期望的那样在 Base 中查找

sudo salt-call state.show_top --log-level=debug

[DEBUG   ] Could not find file 'salt://top.sls' in saltenv 'development'
[DEBUG   ] No contents found in top file. If this is not expected, verify that the 'file_roots' specified in 'etc/mas
ter' are accessible. The 'file_roots' configuration is: {'production': [], 'development': [], 'staging': [], 'base':
[]}
[ERROR   ] The 'development' saltenv has no top file, and the fallback saltenv specified by default_top (base) also h
as no top file

[DEBUG   ] Could not find file 'salt://top.sls' in saltenv 'development'
[DEBUG   ] No contents found in top file. If this is not expected, verify that the 'file_roots' specified in 'etc/mas
ter' are accessible. The 'file_roots' configuration is: {'production': [], 'development': [], 'staging': [], 'base':
[]}
[ERROR   ] The 'development' saltenv has no top file, and the fallback saltenv specified by default_top (base) also h
as no top file

[DEBUG   ] Could not find file 'salt://top.sls' in saltenv 'development'
[DEBUG   ] No contents found in top file. If this is not expected, verify that the 'file_roots' specified in 'etc/mas
ter' are accessible. The 'file_roots' configuration is: {'production': [], 'development': [], 'staging': [], 'base':
[]}
[ERROR   ] The 'development' saltenv has no top file, and the fallback saltenv specified by default_top (base) also has no top file

那么,在 Base 中实现单个 top.sls 以及 saltenv 中的所有其他状态的最佳方法是什么?

干杯。

相关内容