學習的啥也不是
阿新 • • 發佈:2018-04-01
ansible zabbix 部署 自動化 啥廢話也不說!!
主題一:磁盤格式化,可在線擴容
- hosts: all remote_user: root tasks: - name: pvcreate disk shell: pvcreate {{ item }} with_items: - /dev/vdb register: pvcreate_result ignore_errors: False - name: pvcreate display shell: pvdisplay {{ item }} with_items: - /dev/vdb - name: vgcreate disk shell: vgcreate -s 4M vg_mascloud {{ item }} with_items: - /dev/vdb register: vgcreate_result ignore_errors: False when: pvcreate_result | success - name: vgcreate display shell: vgdisplay {{ item }} with_items: - vg_mascloud - name: lvcreate vg_mascloud shell: lvcreate -l +100%FREE -n lv_mascloud {{ item }} with_items: - vg_mascloud register: lvcreate_result ignore_errors: False when: vgcreate_result | success - name: lvcreate display shell: lvdisplay /dev/vg_mascloud/{{ item }} register: lvcreate_result ignore_errors: False with_items: - lv_mascloud - name: mke2fs ext4 lv_mascloud shell: mke2fs -t ext4 /dev/vg_mascloud/{{ item }} with_items: - lv_mascloud register: mke2fs_result ignore_errors: False when: lvcreate_result | success - name: check disk format shell: blkid /dev/vg_mascloud/{{ item }} with_items: - lv_mascloud when: mke2fs_result | success
主題二:編譯安裝zabbix_agent3.2
pwd:/etc/ansible/roles/zabbix/tasks more main.yml - name: Yum Repo synchronize: src: /etc/yum.repos.d/ dest: /etc/yum.repos.d/ mode: push register: synchronize_result ignore_errors: False - name: Change Yum Mode file: path=/etc/yum.repos.d owner=root group=root mode=755 recurse=yes when: synchronize_result | success - name: Clean Yum shell: yum clean all && yum repolist - name: Yum Install Rely On Packages shell: yum install wget vim -y register: yum_result ignore_error: False - name: Create Zabbix Group shell: groupadd zabbix - name: Create Zabbix User shell: useradd -g zabbix -s /sbin/nologin zabbix - name: Mkdir Zabbix Dir file: path=/opt/zabbix/{{ item }} state=directory mode=755 owner=root group=root with_items: - zabbix-agent - logs - pid - name: Get Zabbix Tar ##在Get Tar包這一步,換成copy或者synchronize比較好,自己測試20臺,有4-6臺沒有get下來 shell: cd /opt/zabbix && wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.2.3/zabbix-3.2.3.tar.gz --no-check-certificate register: get_result ignore_errors: False when: yum_result | success - name: Tar zabbix shell: cd /opt/zabbix/ && tar -xf zabbix-3.2.3.tar.gz register: tar_result ignore_errors: False when: get_result | success - name: make zabbix shell: cd /opt/zabbix/zabbix-3.2.3 && ./configure --prefix=/opt/zabbix/zabbix-agent --enable-agent && make && make install register: zabbix_make_result ignore_errors: False when: tar_result | success - name: BackUp Zabbix-Agent Configure shell: cp /opt/zabbix/zabbix-agent/etc/zabbix_agentd.conf /opt/zabbix/zabbix-agent/etc/zabbix_agentd.conf.bak register: back_configtion when: zabbix_make_result | success - name: Change Zabbix-Agent Configure lineinfile: dest: /opt/zabbix/zabbix-agent/etc/zabbix_agentd.conf regexp: "{{ item.regexp }}" line: "{{ item.line }}" with_items: - { regexp: ‘^# PidFile=‘,line: "PidFile=/opt/zabbix/pid/zabbix.pid" } - { regexp: ‘^LogFile=‘,line: "LogFile=/opt/zabbix/logs/zabbix.log" } - { regexp: ‘^# ListenPort=‘,line: "ListenPort=10050" } - { regexp: ‘^Server=‘,line: "Server=192.168.1.23" } - { regexp: ‘^Hostname=‘,line: "Hostname={{ ansible_hostname }}" } - { regexp: ‘^ServerActive=‘,line: "ServerActive=192.168.1.23" } - { regexp: ‘^# Timeout=‘,line: "Timeout=30" } # - { regexp: ‘^Server=‘,line: "Server={{ ansible_eth0[‘ipv4‘][‘address‘]}}"} register: change_configtion ignore_errors: False when: back_configtion | success - name: create zabbix_agent shell: cd /opt/zabbix/zabbix-3.2.3/misc/init.d/fedora/core && cp zabbix_agentd /etc/rc.d/init.d/zabbix_agent when: change_configtion | success register: cp_result ignore_errors: False - name: change zabbix_agent mode shell: chmod +x /etc/rc.d/init.d/zabbix_agent && chkconfig --add zabbix_agent when: cp_result | success - name: ln zabbix_agent to local shell: ln -sv /opt/zabbix/zabbix-agent/sbin/zabbix_agentd /usr/local/sbin when: cp_result | success - name: Change ALL Mode shell: chown -R zabbix.zabbix /opt/zabbix pwd:/root/scripts more zabbix.yml - hosts: mgw01 remote_user: root roles: - zabbix
在使用zabbix-agent的playbook時,需要確定被監控端服務器的主機名,要不然zabbix-server頁面的host主機名會很亂,沒有統一性
批量免秘鑰、修改主機名,可以查看我之間的博客
學習的啥也不是