ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。Ansible架构相对比较简单,仅需通过SSH连接客户机执行任务即可,ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。

playbook实际是把多个不同的任务集合到一个ansible可执行yaml文件中,playbook有严格的缩进规范,实战示例:

 1 ---
 2 - name: deploy logs_monitor
 3   hosts: 192.168.36.1
 4   gather_facts: false
 5   become: yes
 6 
 7   tasks:
 8 
 9     - name: copy log_scripts
10       copy:
11         src: "/ap/sh/log/"
12         dest: "/ap/sh/log/"
13         owner: root
14         group: root
15         mode: 0755
16 
17     - name: copy custom_scripts
18       copy:
19         src: "{{ item.src }}"
20         dest: "{{ item.dest }}"
21         owner: root
22         group: root
23         mode: 0755
24       with_items:
25          - {src: "/root/get_Storage_monitor.py", dest: "/root/" }
26          - {src: "/root/get_gluster_data.py", dest: "/root/" }
27 
28     - name: set cron job
29       cron:
30         name: "execute logs_scripts"
31         job: "{{ item.job }}"
32         minute: "{{ item.minute }}"
33         user: root
34         mode: 0755
35       with_items:
36          - {job: "/root/get_Storage_monitor.py", minute: "5" }
37          - {job: "/root/get_gluster_data.py", minute: "1" }
38          - {job: "/ap/sh/log/6.sh", minute: "5" }
39          - {job: "/ap/sh/logs8.sh", minute: "5" }

 

posted on 2023-09-01 18:34  Albert_M  阅读(34)  评论(0编辑  收藏  举报