在您接受每个密钥后,从Salt-Master发送一个命令,以验证您的Salt Minions是否正在侦听:
[root@zabbix minions]# salt -G 'os:CentOS' test.ping
zabbix.aniu.so:
True
jenkins.aniu.so:
True
[root@zabbix minions]# salt -L 'zabbix.aniu.so,jenkins.aniu.so' test.ping
zabbix.aniu.so:
True
jenkins.aniu.so:
True
[root@zabbix salt]# cat top.sls
base:
'*':
- init.env_init
prod:
'*':
- init.test
salt ‘*’ state.sls init.nettools test=True env=base
salt ‘*’ state.sls init.test test=True env=prod # 测试执行
salt ‘*’ state.sls init.test env=prod # 执行
install vim:
pkg.installed:
- name: vim
remove vim:
pkg.removed:
- name: vim
create my_new_directory:
file.directory:
- name: /opt/my_new_directory
- user: root
- group: root
- mode: 755
Make sure the mysql service is running:
service.running:
- name: mysql
Install mysql and make sure the mysql service is running:
pkg.installed:
- name: mysql
service.running:
- name: mysql
#
Make sure the redis service is running and enable it to start at boot:
service.running:
- name: redis
- enable: True
https://github.com/saltstack/salt-bootstrap:
git.latest:
- rev: develop
- target: /tmp/salt
#
Clone the SaltStack bootstrap script repo:
pkg.installed:
- name: git # make sure git is installed first!
git.latest:
- name: https://github.com/saltstack/salt-bootstrap
- rev: develop
- target: /tmp/salt
user account for yunwei:
user.present:
- name: yunwei
- shell: /bin/bash
- home: /home/yunwei
- groups:
- sudo
gitlab in hosts file:
host.present:
- name: gitlab.aniu.so
- ip: 192.168.0.55
restart redis:
module.run:
- name: service.restart
- m_name: redis # m_name gets passed to the execution module as "name"
执行功能(“远程执行功能”的缩写)是从salt命令行调用的命令,它们以salt.module *开头
ftpusername: me
ftppassword: oxfm4@8t5gglu^h^&
sync directory using lftp:
cmd.run:
- name: lftp -c "open -u {{ pillar['ftpusername'] }},{{ pillar['ftppassword'] }}
-p 22 sftp://example.com;mirror -c -R /local /remote"
salt '*' state.apply ftpsync pillar='{"ftpusername": "test", "ftppassword": "0ydyfww3giq8"}'
include:
- lftp
sync directory using lftp:
cmd.run:
- name: lftp -c "open -u {{ pillar['ftpusername'] }},{{ pillar['ftppassword'] }}
-p 22 sftp://example.com;mirror -c -R /local /remote"
必需条件允许您明确指定状态中的ID的依赖关系。如果添加一个表示id1需要id4的语句,则首先应用id4。
salt ‘zabbix.aniu.so’ state.show_sls init.git env=base
Jinja最常见的用途之一是将条件语句插入Salt柱文件。 因为许多发行版具有不同的包名称,您可以使用os grain来设置平台特定的路径,包名称和其他值。
{% if grains['os_family'] == 'RedHat' %}
apache: httpd
git: git
{% elif grains['os_family'] == 'Debian' %}
apache: apache2
git: git-core
{% endif %}
将上面的代码片段保存到saltstack / columns / common.sls文件中,然后运行以下命令进行刷新,然后列出每个子节点的Salt柱值 salt ‘*’ saltutil.refresh_pillar salt ‘*’ pillar.items
{% for usr in ['yunwei','dev','dba'] %}
{{ usr }}:
user.present
{% endfor %}
#
{% for DIR in ['/tmp/dir1','/tmp/dir2','/tmp/dir3'] %}
{{ DIR }}:
file.directory:
- user: root
- group: root
- mode: 774
{% endfor %}
backup saltstack master file:
file.managed:
- name: /tmp/master
- source: salt://files/master
update master file:
file.append:
- name: /tmp/master
- text: "# test fileappend function."
copy some files to the web server:
file.recurse:
- name: /var/www/html
- source: salt://files/www