[root@master ~]# cd /srv/salt/base/  [root@master base]# ll  总用量 12  -rw-r--r-- 1 root root 172 11月 14 21:26 apache.sls  -rw-r--r-- 1 root root 128 11月 16 00:12 dns.sls  drwxr-xr-x 2 root root  25 11月 16 00:23 files  -rw-r--r-- 1 root root  28 11月 16 00:22 top.sls  [root@master base]# vim dns.sls  [root@master base]# cat dns.sls  /etc/resolv.conf:    file.managed:       - source: salt://files/resolv.conf       - user: root       - group: root       - mode: 777       - template: jinja       - defaults:    #定义变量         DNS_SERVER: 192.168.43.118    [root@master base]# vim files/resolv.conf  [root@master base]# cat files/resolv.conf  #jjjjjjjjjjjjjjjjjj  nameserver {{ DNS_SERVER }}   #2个大括号表示变量    [root@master base]# salt '*'  state.highstate  192.168.43.118:  ----------            ID: /etc/resolv.conf      Function: file.managed        Result: True       Comment: File /etc/resolv.conf updated       Started: 00:43:27.222821      Duration: 21.809 ms       Changes:                ----------                diff:                    ---                    +++                    @@ -1,2 +1,3 @@                     #jjjjjjjjjjjjjjjjjj                    -nameserver 192.168.43.1                    +nameserver 192.168.43.118                    +    Summary  ------------  Succeeded: 1 (changed=1)  Failed:    0    [root@master base]# vim files/resolv.conf  [root@master base]# cat files/resolv.conf  #jjjjjjjjjjjjjjjjjj  #  {{ grains['fqdn_ip4'] }}  nameserver {{ DNS_SERVER }}  [root@master base]# salt '*'  state.highstate  192.168.43.118:  ----------            ID: /etc/resolv.conf      Function: file.managed        Result: True       Comment: File /etc/resolv.conf updated       Started: 00:47:03.799795      Duration: 32.514 ms       Changes:                ----------                diff:                    ---                    +++                    @@ -1,3 +1,3 @@                     #jjjjjjjjjjjjjjjjjj                    +#  ['192.168.43.118']                     nameserver 192.168.43.118                    -    Summary  ------------  Succeeded: 1 (changed=1)  Failed:    0  

系统初始化配置:

[root@master base]# pwd  /srv/salt/base  [root@master base]# mkdir init  [root@master base]# mv apache.sls dns.sls files/ /tmp/  [root@master base]# tree  .  ├── init  └── top.sls    1 directory, 1 file    [root@master base]# cp /tmp/dns.sls init/  [root@master base]# ll  总用量 4  drwxr-xr-x 2 root root 21 11月 16 00:55 init  -rw-r--r-- 1 root root 28 11月 16 00:22 top.sls  [root@master base]# cd init/  [root@master init]# ls  dns.sls    [root@master init]# vim dns.sls  [root@master init]# cat dns.sls  /etc/resolv.conf:    file.managed:       - source: salt://init/files/resolv.conf       - user: root       - group: root       - mode: 777    [root@master init]# mkdir files  [root@master init]# cp /etc/resolv.conf files/  [root@master init]# cp /etc/resolv.conf files/  [root@master init]# vim history.sls  [root@master init]# cat history.sls  /etc/profile:    file.append:  #file模块的追加方法      - text:        - export HISTTIMEFORMAT="%F %T 'whoami'"    [root@master init]# export  PROMPT_COMMAND=' { msg=$(history 1 | { read x y; echo $y; });logger "[eu:$(who am i):['pwd']"$msg";} '  [root@master init]# who  root     pts/0        2018-11-16 00:29 (desktop-4a0ohej)  root     pts/1        2018-11-16 00:38 (desktop-4a0ohej)  [root@master init]# tail -f /var/log/messages  Nov 16 01:01:01 master systemd: Starting Session 34 of user root.  Nov 16 01:10:01 master systemd: Started Session 35 of user root.  Nov 16 01:10:01 master systemd: Starting Session 35 of user root.  Nov 16 01:14:00 master root: [eu { msg=$(history 1 | { read x y; echo $y; });logger "[eu:$(who am i):['pwd']"$msg";} '  Nov 16 01:14:04 master root: [eu { msg=$(history 1 | { read x y; echo $y; });logger "[eu:$(who am i):['pwd']"$msg";} '    [root@master init]# cat sysctl.sls  vm.swappinese:   #尽量不适用swap分区    sysctl.present:      - value: 0    net.ipv4.ip_local_port_range:    sysctl.present:      - value: 10000 65000    fs.file-max:    #最大打开文件数    sysctl.present:      - value: 100000    [root@master init]# vim env_init.sls  [root@master init]# cat env_init.sls  include:    - init.dns    - init.history    - init.audit    - init.sysctl    [root@master init]# cd ..  [root@master base]# ls  init  top.sls  [root@master base]# vim top.sls  [root@master base]# cat top.sls  base:    '*':      - init.env_init  #在base路径下去init目录找env_init文件并执行    [root@master base]# salt '*' state.highstate test=True  测试不执行  [root@master base]# salt '*' state.highstate  

原文出处:51cto -> http://blog.51cto.com/13399294/2324553

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。
超哥软件库 » saltstack的jinja模