具有單一 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.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 中的所有其他狀態的最佳方法是什麼?

乾杯。

相關內容