ansible在linux和windows批量部署zabbix-agent2
---
- hosts: linux
tasks:
- name: copy centos 7 zabbix-agent2
copy: src=zabbix-agent2-5.0.11-1.el7.x86_64.rpm dest=/root
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- name: install centsos 7 agent2
shell: rpm -ivh /root/zabbix-agent2-5.0.11-1.el7.x86_64.rpm
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- name: copy centos 6 agent2
copy: src=zabbix-agent2-5.0.11-1.el6.x86_64.rpm dest=/root
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
- name: install centos 6 agent2
shell: rpm -ivh /root/zabbix-agent2-5.0.11-1.el6.x86_64.rpm
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
- name:
shell: cp /etc/zabbix/zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf.bak && sed -i 's/127.0.0.1/172.20.100.99/g' /etc/zabbix/zabbix_agent2.conf
notify: restart zabbix-agent2
handlers:
- name: restart zabbix-agent2
service: name=zabbix-agent2 enabled=yes state=started
zabbix下载地址:http://repo.zabbix.com/zabbix/5.0 ansible-playbook -l linux zabbix.yml
在windows上批量安装zabbix-agent2
下载地址:zabbix-agent2下载地址:https://cdn.zabbix.com/zabbix/binaries/stable/5.0/5.0.11/zabbix_agent2-5.0.11-windows-amd64-openssl-static.zip
在windows上执行以下命令:
winrm quickconfig
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service @{AllowUnencrypted="true"}
或者写成脚本在powershell执行
@ECHO off
winrm quickconfig -q -force
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service @{AllowUnencrypted="true"}
New-NetFirewallRule -Name Ansible -DisplayName Ansible -Enabled True -Action Allow -Protocol TCP -LocalPort 5985 -Direction InBound
PAUSE
防火墙放开5985端口
---
- hosts: all
tasks:
- name: Firewall rule to allow ansible om tcp port 5985
action: win_firewall_rule
args:
name: ansible
enabled: yes
state: present
localport: 5985
action: allow
protocol: Tcp
执行ansible-playbook -l windows win_rule_5985.yml
或者ansible-playbook -i hosts windows win_rule_5985.yml
ansible-playbook -i hosts win_rule_5985.yml -e hosts=windows
---
- hosts: Ali-windows
remote_user: Administrator
vars:
zabbix_server_ip: 59.37.126.227
tasks:
- name: create zabbix-agent2 dir
win_file:
path: C:zabbix-agent2
state: directory
- name: copy zabbix-agent2 file
win_template: src=/etc/ansible/windows/roles/zabbix/templates/zabbix_agent2.conf dest=C:\zabbix-agent2\
- name: copy zabbix-agent2
win_copy: src=zabbix_agent2.exe dest=C:\zabbix-agent2\
- name: Install windows zabbix-agent2
#win_package:
# path: C:\zabbix_agent2-5.0.11-windows-amd64-openssl.msi
#Zabbix server IP: zabbix_server_ip
#arguments:
#- /install
#- /norestart
#state: present
win_command: zabbix_agent2.exe -i -c C:\zabbix-agent2\zabbix_agent2.conf
args:
chdir: C:\zabbix-agent2\
- name: start zabbix-agent2
win_command: zabbix_agent2.exe -s -c C:\zabbix-agent2\zabbix_agent2.conf
args:
chdir: C:\zabbix-agent2\
- name: Firewall rule to allow zabbix-agent2 om tcp port 10050
action: win_firewall_rule
args:
name: zabbix-agent2
enabled: yes
state: present
localport: 10050
action: allow
protocol: Tcp

浙公网安备 33010602011771号