ansible自动部署zabbix-agent的模块

author author     2022-09-09     280

关键词:

ansible自动部署 zabbix-agent 模块  的准备阶段  

ansible所在的服务端可以免密钥登录所被部署的机器称为客户端。

免密钥的做法

服务端 ssh-keygen  一路回车生成密钥对 

ssh-copy-id 指定IP 将公钥发给指定的ip 即可 

ssh-copy-id 192.168.1.18 


下面红色是代表文件或目录  黑色字体代表是内容 


使用了 roles 方法  整体的目录结构是

/etc/ansible/zabbix-agent.yml

[[email protected] ansible]# pwd

/etc/ansible


/etc/ansibl/hosts

[[email protected] ansible]# cat hosts


192.168.1.145  #centso 系统 

192.168.1.147  #   centos 系统   加入 ansible 的客户端ip  本次示例中是这几个 ip  

192.168.1.148  #ubuntu 系统


[[email protected] ansible]# cat zabbix-agent.yml 

---

- hosts: all

  roles:

    - zabbix-agent



/etc/ansible/roles


[[email protected] ansible]#  ls

zabbix-agent


/etc/ansible/zabbix-agent



[[email protected] zabbix-agent]# ls

files  handlers  tasks  templates


/etc/ansible/zabbix-agent/files  


[[email protected] zabbix-agent]# ls files/

zabbix


/etc/ansible/zabbix-agent/handlers


[[email protected] zabbix-agent]# ls handlers/

main.yml


/etc/ansible/zabbix-agent/tasks



[[email protected] zabbix-agent]# ls tasks/

files.yml  main.yml  package.yml  service.yml



/etc/ansible/zabbix-agnet/templates



[[email protected] zabbix-agent]# ls templates/

zabbix_agentd.conf



/etc/ansible/zabbix-agent/files/zabbix/conf.d


[[email protected] zabbix-agent]# ls files/zabbix/conf.d/  #zabbix-agent的配置文件 键值

impression.conf  imsecret.conf  mystar.conf  resonance.conf  tagme.conf  userReg.conf


/etc/ansible/zabbix-agent/files/zabbix/scripts 要复制去客户端的文件


[[email protected] zabbix-agent]# ls files/zabbix/scripts/  下边是zabbix 可执行的脚本用来监控 

/etc/ansible/zabbix-agent/handlers/main.yml  这个是开启zabbix-agent的 


[[email protected] zabbix-agent]# cat handlers/main.yml 

---

- name: start zabbix_agentd

  service: name=zabbix-agentd state=started


/etc/ansible/zabbix-agent/tasks/files.yml 将 /etc/ansible/zabbix-agent/files/* 复制到客户端的配置


[[email protected] zabbix-agent]# cat tasks/files.yml 

---

- name: copy centos template conf file

  template: src=zabbix_agentd.conf  dest=/etc/

  when: ansible_os_family == "RedHat" #判断系统 


- name: copy ubuntu template conf file

  template: src=zabbix_agentd.conf  dest=/etc/zabbix/

  when: ansible_os_family == "Debian"


- name: crete conf.d and scripts

  file: path={{ item }} state=directory owner=root group=root mode=0755

  with_items:

  - /etc/zabbix/scripts

  - /etc/zabbix/conf.d

  - /etc/zabbix/scripts1


- name: copy the scripts/file

  copy: src=zabbix/scripts/ dest=/etc/zabbix/scripts/ mode=0755


- name: copy the scripts1/file 

  copy: src=zabbix/scripts1/ dest=/etc/zabbix/scripts1/ mode=0755


- name: copy the conf.d/file 

  copy: src=zabbix/conf.d/ dest=/etc/zabbix/conf.d/


/etc/ansible/zabbix-agent/tasks/main.yml 主的配置 在同级目录下会先执行这个main


[[email protected] zabbix-agent]# cat tasks/main.yml 

---

- include: ‘package.yml‘

- include: ‘files.yml‘

- include: ‘service.yml‘



/etc/ansible/zabbix-agent/tasks/package.yml 安装zabbix-agent的配置


[[email protected] zabbix-agent]# cat tasks/package.yml 

---

- name: useraddd the zabbix

  user: name=zabbix


- name: install epel-release

  yum: name=epel-release.noarch state=latest

  when: ansible_os_family == "RedHat"


- name: install epel-release and  zabbix_agent_package

  yum: name={{ item }} state=present

  with_items:

  - zabbix22-agent-2.2.18-1.el6.x86_64

  - zabbix22-2.2.18-1.el6.x86_64

  when: ansible_os_family == "RedHat"


- name: apt-get install to ubuntu 

  apt: name={{ item }} state=present

  with_items:

  - zabbix-agent 

  when: ansible_os_family == "Debian"



/etc/ansible/zabbix-agent/tasks/service.yml   开启脚本 万无一失  2重开启


[[email protected] zabbix-agent]# cat tasks/service.yml 

---

- name: start zabbix-agentd

  service: name=zabbix-agentd state=started

  when: ansible_os_family == "RedHat"


- name: start ubuntu zabbix-agent

  service: name=zabbix-agent state=started

  when: ansible_os_family == "Debian"



/etc/ansible/zabbix-agent/templates/zabbix_agentd.conf  配置文件的模板放在这里 



[[email protected] zabbix-agent]# cat templates/zabbix_agentd.conf 

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

LogFileSize=100

Server=192.168.1.100  #zabbix 服务端所在的 ip 

ServerActive=192.168.1.100  # zabbix-agent 主动模式 配置 

Hostname={{ ansible_hostname }}  #这个是系统变量

Include=/etc/zabbix/conf.d/

UnsafeUserParameters=1

# UserParameter  自定义的 监控项 


具体执行 

[[email protected] ansible]# pwd

/etc/ansible

[[email protected] ansible]# ansible-playbook zabbix-agent.yml  

[[email protected] ansible]# ansible-playbook zabbix-agent.yml   -vvvv

加  -vvv  可以看到更详细的过程  其实是 没必要的  


本文出自 “手有余香” 博客,请务必保留此出处http://19941018.blog.51cto.com/11889001/1949589

使用ansible-playbook部署zabbix-agent-4.0(代码片段)

-hosts:allremote_user:roottasks:-name:CentOS6systemcopyzabbix-agentrpmcopy:src=/tmp/zabbix-agent-3.4.9-1.el6.x86_64.rpmdest=/tmp/zabbix-agent-3.4.9-1.el6.x86_64.rpmwhen:-ansible_distribution=="CentOS" 查看详情

ansible-playbookagent实例

...》华章出的也看了80多页了,就试着写了一个agent推送和zabbix-agent推送,主要是发布系统agent推送,之前的zabbix-agent推 查看详情

ansible自动化运维之ansible入门及简单部署(代码片段)

AnsibleAnsible简介Ansible特点概念解释Ansible使用过程中的角色Ansible通信机制Ansible应用场景Ansible工作机制Ansible的目录结构部署环境Ansible部署添加远程主机Ansible简介常见的部署管理工具有Chef、Puppet、Ansible、SaltStack、Fabric。Ansible发... 查看详情

自动化工具-ansible服务部署与使用

1.前言1.1ansible软件介绍python语言是运维人员必须会的语言ansible是一个基于python开发的自动化运维工具其功能实现基于ssh远程连接服务ansible可以实现批量系统配置,批量软件部署,批量文件拷贝,批量运行命令等功能除了ansible之... 查看详情

ansible自动化部署k8s集群

一、Ansible自动化部署K8S集群1.1Ansible介绍Ansible是一种IT自动化工具。它可以配置系统,部署软件以及协调更高级的IT任务,例如持续部署,滚动更新。Ansible适用于管理企业IT基础设施,从具有少数主机的小规模到数千个实例的企... 查看详情

自动化运维工具ansible的详细部署(代码片段)

Ansible的来历Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。 Ansible是基于paramiko开发的,并且基于模块化工... 查看详情

自动化运维之ansible服务部署(代码片段)

Ansible简介Ansible使用Python语言开发,巧妙的设计、实现了简单易用、功能强大的自动化管理工具。目前它已经广泛应用于各种规模、各个领域的企业。Ansible应用领域Ansible的编排引擎可以出色地完成配置管理、流程控制、资源部... 查看详情

[自动化]部署ansible服务及其常用的命令模块(代码片段)

Ansible简介:Ansible基于Python开发,默认通过SSH协议进行远程命令执行或下发配置,无需部署任何客户端代理软件,可同时支持多台主机进行管理。ansible是基于模块工作的,本身没有批量部署的能力,真正具有批量部署的是ansible... 查看详情

安装部署自动化运维之ansible(代码片段)

初步了解Ansibleansible基于Python开发,,集合了众多运维工具的优点,实现了批量运行命令,部署程序,配置系统等功能。默认通过SSH协议进行远程命令执行或下发配置,无需部署任何客户端代理软件,从而使得自动化环境部署变... 查看详情

自动化运维工具ansible(代码片段)

学习Ansible的系列文章Ansible介绍Ansible架构Ansible安装Ansible配置文件及参数Ansible常用模块Ansibleplaybook1.Ansible介绍Ansible是一个配置管理和应用部署工具,只需要通过ssh访问服务器或设备即可实现批量系统配置、程序部署、运行命令... 查看详情

自动化运维之ansible的安装部署与命令模块(代码片段)

Ansible简介Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量... 查看详情

自动化运维之ansible-安装部署与基础命令篇(代码片段)

一、Ansible简介Ansible基于Python语言开发,集合了众多优秀运维工具的优点,实现了批量运行命令、部署程序、配置系统等功能。二、安装部署Ansible服务Ansible自动化运维环境由控制主机与被管理主机组成,由于Ansible是基于SSH协议... 查看详情

elastic:如何使用ansible自动化部署elasticstack-security(代码片段)

在之前我的系列文章:如何使用Ansible自动化部署ElasticStack-Overview(一)如何使用Ansible自动化部署ElasticStack-Elasticsearch(二)如何使用Ansible自动化部署ElasticStack-Kibana(三)我们已经学习了如何使用Ansible 查看详情

ansible集中化自动管理(部署lamp环境)

##ansible集中化自动管理目标:1、生成公钥,并上传ssh的公钥到被控端主机   2、在ansible的主控端配置本地yum源和网络yum源   3、安装ansible,用ansible上传yum源目录到被控端主机。   4、用ansible管理... 查看详情

jenkins+ansible+gitlab自动化部署三剑客

最近一直在学习Ansible的一些playbook的写法,所以一直没有怎么更新,想到目前大家对诸如saltstack,docker, Ansible等自动化部署相关的工具很感兴趣,但又苦于没有可学习的中文实例,这里我就把我这几个月所接触到目前国外比较流行... 查看详情

ansible自动化部署zabbix客户端

本文主要介绍使用ansibleplaybook中roles,在不同os版本下批量部署zabbix客户端。一、facts介绍playbook的部分fetch信息ansible版本2.2.1.0使用setup模块获取# ansible 192.168.1.12 -m setup"ansible_distribution": "CentOS",  查看详情

02.使用ansible自动化部署redis集群

参考技术Aansible作为一款自动化软件工具,不需要修改配置文件就可以直接启动ansible的目录结构:官方地址:官方的目录定义:根据官方的目录规划,依次创建目录: 查看详情

ansible自动化运维详解ansible的安装部署参数使用清单管理配置文件参数及用户级ansible操作环境构建(代码片段)

文章目录ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建一、ansible的安装部署1.1、ansible简介1.2、实验环境1.3、安装部署ansible二、ansible的基本信息和参数使... 查看详情