ansible-playbook

1、目录规则

 

2、编写脚本

2.1,设置主机 host文件

[hr]
10.10.1.71 ansible_ssh_user=developer ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method="su" ansible_become_pass=" "
10.10.1.72 ansible_ssh_user=developer ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method="su" ansible_become_pass=" "
10.10.1.73 ansible_ssh_user=developer ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method="su" ansible_become_pass=" "
10.10.1.74 ansible_ssh_user=developer ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method="su" ansible_become_pass=" "

[app]
10.10.1.55 ansible_ssh_user=developer ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method='su' ansible_become_pass=""
10.10.1.15 ansible_ssh_user=devops    ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method='su' ansible_become_pass=" "
10.10.1.40 ansible_ssh_user=developer ansible_ssh_port=23798 ansible_ssh_pass=""  ansible_become_user="root" ansible_become_method='su' ansible_become_pass=" "

2.2 编写 install_zabbix_agent.yml

- hosts: other
  become: yes
  roles:
  - install_zabbix_agent

2.3编写roles/install_zabbix_agent/tasks/main.yml 


- name: install software
  yum: name={{item}} state=latest
  with_items:
    - libcurl
    - libcurl-devel
- name: create zabbix user
  user: name={{zabbix_user}} state=present shell=/sbin/nologin
- name: create a dir
  file: path={{zabbix_dir}}/etc owner={{zabbix_user}} group={{zabbix_user}} mode=0775 state=directory
- name: Uncompression Zabbix.tar.gz
  unarchive: src=zabbix-{{zabbix_version}}.tar.gz dest={{zabbix_dir}}
- name: copy zabbix start script
  template: src=zabbix_agentd dest=/etc/rc.d/init.d/zabbix_agentd owner=root group=root mode=0755
- name: compile zabbix
  shell: cd {{zabbix_dir}}/zabbix-{{zabbix_version}};./configure --with-net-snmp --with-libcurl --enable-agent --prefix={{zabbix_dir}}
- name: make
  shell: cd {{zabbix_dir}}/zabbix-{{zabbix_version}};make && make install
- name: copy zabbix config file
  template: src=zabbix_agentd.conf dest={{zabbix_dir}}/etc/zabbix_agentd.conf owner={{zabbix_user}} group={{zabbix_user}}  mode=0644
- name: modify zabbix dir permission
  file: path={{zabbix_dir}}/zabbix owner={{zabbix_user}} group={{zabbix_user}} recurse=yes
- name: start zabbix service
  shell: /etc/init.d/zabbix_agentd stop;/etc/init.d/zabbix_agentd start
~                                                                        

4、files 用于存档需要复制的文件,templates是模板, vars是变量

5 执行ansible-playbook  install_zabbix_agent.yml -b

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值