admin

ansible-playbook 安装zabbix5.0客户端

admin 高可用/自动化 2021-08-02 66浏览 0

ansible-playbook 安装zabbix客户端yml脚本


---                      
- hosts: all
  remote_user: root
  vars:
    zabbix_server: 192.168.0.11
  tasks:
    - name: disable Selinux
      shell: "setenforce 0"
      failed_when: false      
    - name: change Selinux config
      lineinfile: 
        dest: /etc/selinux/config
        regexp: '^SELINUX='
        line: 'SELINUX=disabled'        
     
    - name: Firewalld disable
      service: name=firewalld state=stopped enabled=no      
      
    ########Ulimit Init########
    - name: Ulimit change
      shell: ulimit -HSn 65535;ulimit -u 81920
    - name: Change limits.conf nofile
      lineinfile:
        dest: /etc/security/limits.conf
        regexp: '\* - nofile [0-9]+'
        #backrefs: no
        line: '* - nofile 65535'
    - name: Change limits.conf nproc
      lineinfile:
        dest: /etc/security/limits.conf
        regexp: '\* - nproc [0-9]+'
        #backrefs: no
        line: '* - nproc 81920'
    
    - name: check hosts ipaddress
      shell: ip addr |grep global |grep $(route  |grep default |awk '{print $NF}') |head -n1 |awk '{print $2}' |cut -d '/' -f1
      register: hostaddr
    - name: print ipaddress
      debug: msg="---------------{{ hostaddr['stdout'] }}----------------"
    - name: install zabbix rpm source
      yum:
        name: https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
        state: installed
    - name: Modify to aliyun Yum source
      shell: sed -i 's@repo.zabbix.com@mirrors.aliyun.com/zabbix@g' /etc/yum.repos.d/zabbix.repo
    - name: yum install zabbix-agent
      yum: name="zabbix-agent"
    - name: create zabbix log
      shell: mkdir -p /var/log/zabbix && touch /var/log/zabbix/zabbix_agentd.log && chown -R zabbix.zabbix /var/log/zabbix
    - name: Change zabbix_agentd.conf Server
      lineinfile:
        dest: /etc/zabbix/zabbix_agentd.conf
        regexp: 'Server='
        #backrefs: no
        line: 'Server={{ zabbix_server }}'
        
    - name: Change zabbix_agentd.conf ServerActive
      lineinfile:
        dest: /etc/zabbix/zabbix_agentd.conf
        regexp: 'ServerActive='
        #backrefs: no
        line: 'ServerActive={{ zabbix_server }}'
        
    - name: Change zabbix_agentd.conf UnsafeUserParameters
      lineinfile:
        dest: /etc/zabbix/zabbix_agentd.conf
        regexp: 'UnsafeUserParameters='
        #backrefs: no
        line: 'UnsafeUserParameters=1'
     
    - name: Change zabbix_agentd.conf hostname
      lineinfile:
        dest: /etc/zabbix/zabbix_agentd.conf
        regexp: 'Hostname='
        #backrefs: no
        line: "Hostname={{ hostaddr['stdout'] }}"
    
    - name: Change zabbix_agentd.conf log 
      lineinfile:
        dest: /etc/zabbix/zabbix_agentd.conf
        regexp: 'LogFile='
        #backrefs: no
        line: 'LogFile=/var/log/zabbix/zabbix_agentd.log'
      
    - name: zabbix_agent start
      service: name=zabbix_agentd state=started enabled=true

示例:

ansible-playbook  -i "192.168.9.129," z.yml 

版权声明

本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。

发表评论
展开