• 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-agent2zabbix_agent2.conf
          args:
            chdir: C:zabbix-agent2
    
        - name: start zabbix-agent2
          win_command: zabbix_agent2.exe -s -c C:zabbix-agent2zabbix_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

     

      

      

  • 相关阅读:
    纯C分割 字符串 devC++版本 vs各种奇怪的问题,
    C的字符串操作 split
    MyArray框架搭建与实现
    三目运算符(C++)
    ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    sqlServer not in 分页
    web 移动端开发手机查看效果
    webpack 安装babel处理ES6语法
    webpack 的环境搭建
    web 服务器添加数据到 SQL server
  • 原文地址:https://www.cnblogs.com/The-day-of-the-wind/p/14793022.html
Copyright © 2020-2023  润新知