公司网站源码 带wap手机站,2021年国内最新新闻,wordpress翻页代码,网站内地图位置怎么做公司的金山区云服务器是由我负责的#xff0c;每一次新购买了金山区的服务器都要把这些新服务器添加到zabbix监控里#xff0c;于是我就编写了一个ansible的playbook#xff0c;这样以后就可以在执行playbook的时候“带薪拉屎”了。 ansible主机准备#xff1a; 1#xff… 公司的金山区云服务器是由我负责的每一次新购买了金山区的服务器都要把这些新服务器添加到zabbix监控里于是我就编写了一个ansible的playbook这样以后就可以在执行playbook的时候“带薪拉屎”了。 ansible主机准备 1准备一个已经填写好zabbix_server同时hostname为空的zabbix_agentd.conf放在/root/路径下 2把新购买的机器ip地址填写到/etc/ansible/hosts里原有的hosts要另外保存一份 3playbook跑完之后具体的自定义项目比如pid、端口检查等监控项就是自己单独配置了 4别忘了去zabbix的web页面确认 整个playbook如下文 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 --- - hosts: all tasks: - name: 给新购买的机器安装zabbix 2.2版本(2.2.14版本 yum: namezabbix22 statelatest yum: namezabbix22-agent statelatest - name: 备份原来的zabbix_agentd.conf shell: mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf-bak - name: 将控制端上的zabbix_agent.conf下发到目标机器 copy: src/root/zabbix_agentd.conf dest/etc/zabbix/ ownerroot grouproot mode0777 - name: 对应更改Hostname shell: sed -i s/Hostname/Hostname$(hostname)/ /etc/zabbix/zabbix_agentd.conf notify: Start Zabbix-agent Service handlers: - name: Start Zabbix-agent Service service: namezabbix-agent startrestarted 执行之后会有一个提示如图 ansible提示最好使用template或者lineinfile模块而不要用sed命令。 既然ansible这么说那咱们就用呗而且再把上面的语言整理一下。如下文 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 --- - hosts: all tasks: - name: 给新购买的机器安装zabbix 2.4版本 yum: name{{ item }} statelatest with_items: - zabbix24 - zabbix24-agent - name: 备份原来的zabbix_agentd.conf shell: mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf-bak - name: 将控制端上的zabbix_agent.conf下发到目标机器 copy: src/root/zabbix_agentd.conf dest/etc/zabbix/ ownerroot grouproot mode0777 - name: 在新的zabbix_agent.conf添加Hostname lineinfile: dest/etc/zabbix/zabbix_agentd.conf regexp^Hostname lineHostnameansible_nodename notify: Start Zabbix-agent Service handlers: - name: Start Zabbix-agent Service service: namezabbix-agent startretarted 多说一下lineinfile模块lineinfile模块具备“文件备份、语句替换、语句删除、新语句插入”功能。其格式是 1 lineinfile: dest目标文件绝对路径 具体内容 其中具体内容可以是以下几项 1backupyes将原来的dest文件备份默认是No 2regexp 接正则表达式本文用的是“^Hostname”即匹配以Hostname开头的行 3state 不单独写出来的话默认是present如果是stateabsent就是把regexp 满足的语句删除 4line要插入的话,如果前面没有regexp匹配出来的语句那么默认是把“要插入的话”插入到文件最后一行。 本文转自 苏幕遮618 51CTO博客原文链接:http://blog.51cto.com/chenx1242/1856628