码迷,mamicode.com
首页 > 其他好文 > 详细

saltstack的jinja模

时间:2018-12-01 00:00:52      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:saltstack   eui   oca   tac   roo   系统初始   括号   ati   code   

[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 "[euid=$(whoami)]":$(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: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]export PROMPT_COMMAND=‘ { msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[‘pwd‘]"$msg";} ‘ Nov 16 01:14:04 master root: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]uptime Nov 16 01:14:39 master root: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]tail -f /var/log/messages Nov 16 01:14:42 master root: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]uptime Nov 16 01:15:06 master root: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]tail -f /var/log/messages Nov 16 01:15:12 master root: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]tail -f /var/log/messages Nov 16 01:15:17 master root: [euid=root]:root pts/0 2018-11-16 00:29 (desktop-4a0ohej):[pwd]who [root@master init]# ll 总用量 12 -rw-r--r-- 1 root root 172 11月 16 01:17 audit.sls -rw-r--r-- 1 root root 137 11月 16 00:57 dns.sls drwxr-xr-x 2 root root 25 11月 16 00:58 files -rw-r--r-- 1 root root 88 11月 16 01:03 history.sls [root@master init]# cat audit.sls /etc/bashrc: file.append: - text: - export PROMPT_COMMAND=‘ { msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(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

saltstack的jinja模

标签:saltstack   eui   oca   tac   roo   系统初始   括号   ati   code   

原文地址:http://blog.51cto.com/13399294/2324553

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!