{"id":651,"date":"2020-03-17T09:26:53","date_gmt":"2020-03-17T01:26:53","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=651"},"modified":"2020-03-17T09:26:54","modified_gmt":"2020-03-17T01:26:54","slug":"ansible-mass-deploy-zabbix-agent","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2020\/03\/ansible-mass-deploy-zabbix-agent\/","title":{"rendered":"Ansible \u6279\u91cf\u90e8\u7f72 Zabbix-agent"},"content":{"rendered":"\n
\nsudo apt update\nsudo apt-get install software-properties-common\nsudo apt-add-repository --yes ppa:ansible\/ansible:2.7.6\nsudo apt update\nsudo apt-get install ansible\n\n<\/pre>\n\n\n\n2.\u6dfb\u52a0ansible \u4e3b\u673a<\/h2>\n\n\n\n
\u4e24\u79cd\u4e0d\u540c\u7684\u7cfb\u7edf\u5b89\u88c5\u65b9\u6cd5\u7565\u5fae\u4e0d\u540c\uff0c\u5206\u4e3a\u4e24\u7ec4\u91c7\u7528\u4e0d\u540cplaybook\nvim \/etc\/ansible\/hosts\n [ubuntu_groups] \n 192.168.0.30 ansible_ssh_private_key_file=\/root\/test.pem\n 192.168.0.10 ansible_ssh_private_key_file=\/root\/test.pem\n [centos7_groups]\n 192.168.0.29 ansible_ssh_private_key_file=\/root\/test.pem\n 192.168.0.28 ansible_ssh_private_key_file=\/root\/test.pem\n 192.168.0.27 ansible_ssh_private_key_file=\/root\/test.pem<\/pre>\n\n\n\n3.\u7f16\u5199playbook<\/h2>\n\n\n\n
vim \/etc\/ansible\/ubuntu.yml (ubuntu \u64cd\u4f5c\u7cfb\u7edf)\n---\n name: ubuntu playbook\n hosts: ubuntu_groups \n remote_user: root\n gather_facts: False\n ignore_errors: True\n tasks:\n name: install zabbix-agent\n shell: apt-get install -y zabbix-agent\n name: Server\n lineinfile:\n backrefs: yes\n path: \/etc\/zabbix\/zabbix_agentd.conf\n regexp: '^Server=127.0.0.1'\n line: 'Server=192.168.0.30'\n name: ServerActive\n lineinfile:\n backrefs: yes\n path: \/etc\/zabbix\/zabbix_agentd.conf\n regexp: '^ServerActive=127.0.0.1'\n line: 'ServerActive=192.168.0.30'\n name: restart\n service:\n name=zabbix-agent\n enabled=yes\n state=restarted <\/pre>\n\n\n\nvim \/etc\/ansible\/centos7.yml (centos7\u64cd\u4f5c\u7cfb\u7edf)\n---\n name: centos7 playbook\n # hosts: centos7_groups\n hosts: fugong\n remote_user: root\n gather_facts: False\n ignore_errors: True\n tasks:\n name: install rpm\n yum:\n name=https:\/\/repo.zabbix.com\/zabbix\/3.2\/rhel\/7\/x86_64\/zabbix-release-3.2-1.el7.noarch.rpm\n state=present\n name: yum makecache\n yum:\n name=*\n update_cache=yes\n name: install agent\n yum:\n name=zabbix-agent\n state=latest\n name: install agent-get\n yum:\n name=zabbix-get\n state=latest\n name: install agent-sender\n yum:\n name=zabbix-sender\n state=latest\n name: Server\n lineinfile:\n backrefs: yes\n path: \/etc\/zabbix\/zabbix_agentd.conf\n regexp: '^Server=127.0.0.1'\n line: 'Server=192.168.0.30'\n name: ServerActive\n lineinfile:\n backrefs: yes\n path: \/etc\/zabbix\/zabbix_agentd.conf\n regexp: '^ServerActive=127.0.0.1'\n line: 'ServerActive=192.168.0.30'\n name: restart\n service:\n name=zabbix-agent\n enabled=yes\n state=restarted <\/pre>\n\n\n\n4.\u68c0\u67e5\u8bed\u6cd5<\/h2>\n\n\n\n
--syntax-check #\u68c0\u67e5Playbook\u4e2d\u7684\u8bed\u6cd5\u4e66\u5199,\u5e76\u4e0d\u5b9e\u9645\u6267\u884c\n --check #\u6a21\u62df\u6267\u884c\uff0c\u4e0d\u4f1a\u771f\u6b63\u5728\u673a\u5668\u4e0a\u6267\u884c(\u67e5\u770b\u6267\u884c\u4f1a\u4ea7\u751f\u4ec0\u4e48\u53d8\u5316)<\/code><\/pre>\n\n\n\n
ansible-playbook --syntax-check centos7.yml\nansible-playbook --syntax-check ubuntu.yml \nansible-playbook --check centos7.yml\nansible-playbook --check ubuntu.yml <\/pre>\n\n\n\n5.\u6267\u884c\u5b89\u88c5<\/h2>\n\n\n\n
ansible-playbook centos7.yml \nansible-playbook ubuntu.yml \n<\/pre>\n\n\n\n6. \u5b8c\u6210<\/h2>\n\n\n\n
\u5982\u679c\u4e00\u5207\u987a\u5229\u7684\u8bddzabbix-agent \u5df2\u7ecf\u5b89\u88c5\u5b8c\u6210\uff0c\u767b\u5f55\u5b89\u88c5\u4e3b\u673a\u68c0\u67e5\u67e5\u770b\u4e0b\u8fdb\u7a0b\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
1.\u5b89\u88c5ansible sudo apt update sudo apt-get install softwa<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,18,33],"tags":[],"yoast_head":"\n
Ansible \u6279\u91cf\u90e8\u7f72 Zabbix-agent - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n