[[email protected] srv]# pwd /srv [[email protected] srv]# ls pillar salt [[email protected] srv]# cat pillar/ data.sls pkg/ top.sls users/ [[email protected] srv]# cat pillar/pkg/init.sls pkgs: {% if grains[‘os_family‘] == ‘RedHat‘ %} vim: vim-enhanced {% elif grains[‘os_family‘] == ‘Debian‘ %} vim: vim {% elif grains[‘os‘] == ‘Arch‘ %} vim: vim {% endif %} [[email protected] srv]# cat pillar/top.sls base: ‘*‘: - data - users - pkg [[email protected] srv]# cat salt/edit/vim.sls vim: pkg: - installed - name: {{ pillar[‘pkgs‘][‘vim‘] }} /root/.vimrc: file.managed: - source: salt://edit/conf/vimrc - mode: 644 - uesr: root - group: root - require: - pkg: vim 执行: [[email protected] srv]# salt ‘svr205-2‘ state.sls edit.vim svr205-2: ---------- ID: vim Function: pkg.installed Name: vim-enhanced Result: True Comment: Package vim-enhanced is already installed. Started: 18:05:24.707048 Duration: 1808.3 ms Changes: ---------- ID: /root/.vimrc Function: file.managed Result: True Comment: File /root/.vimrc is in the correct state Started: 18:05:26.515743 Duration: 153.787 ms Changes: Summary ------------ Succeeded: 2 Failed: 0 ------------ Total states run: 2
时间: 2025-01-06 06:53:37