3.中小型企业通用自动化运维架构 -- Ansible playbook

实战:

---
- hosts: test
  remote_user: root
  tasks:
  - name: Hello World
    shell: ls /root
---
- hosts: test
  remote_user: root
  vars:
    com: /root
  tasks:
  - name: Hello World
    shell: ls {{ com }}
---
- hosts: test
  remote_user: root
  become: true
  tasks:
  - name: install python for centos
    yum:
      name: "{{ item }}"
      state: installed
    with_items:
        - python-devel
        - python-setuptools
    when: ansible_distribution == 'CentOS'
  - name: install python for ubuntu
    apt:
      name: "{{ item }}"
      state: latest
      update_cache: yes
    with_items:
        - libpython-dev
        - python-setuptools
    when: ansible-distribution == 'Ubuntu'
  - name: install pip
    shell: easy_install pip
  - name: pip install flask and redis
    pip:
      name: "{{ item }}"
      with_items:
        - flask
        - redis

 

安装 zabbix:

---
- hosts: test
  become: true
  tasks:
  - name: install zabbix rpm
    yum:
        name: zabbix yum 路径
        state: installed
    when: ansible_distribution == 'CentOS'
  - name: download zabbix deb
    get_url:
        url: deb 路径
        dest: /tmp/zabbix.deb
    when: ansible_distribution == 'Ubuntu'
  - name: install zabbix deb
    apt:
        name: /tmp/zabbix.deb
        state: installed
    when: ansible_distribution == 'Ubuntu'
  - name: install zabbix
    yum:
        name: "{{ item }}"
        state: installed
        with_item:
        - zabbix-server-mysql
        - zabbix-proxy-mysql
        - zabbix-web-mysql
        when: ansible_distribution == 'CentOS'
  - name: config zabbix server
    replace:
        path: /etc/zabbix/zabbix_server.conf
        regexp: DBUser=zabbix
        replace: DBUser=root
    when: ansible_distribution == 'CentOS'
  - name: import db format
    shell: zcat ...
  - name: disable selinux
    selinux:
        state: disabled
   when: ansible_distribution == 'CentOS'
  - name: start zabbix server
    systemd:
        name: zabbix-server
        state: started
    when: ansible_distribution == 'CentOS'
 - name: start zabbix client
   systemd:
        name: zabbix-agent
        state: started
   when: ansible_distribution == 'CentOS'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值