ansible实例

目录

实例一:执行curl命令发送post请求

实例二:直接发送post请求

实例一

执行curl命令发送post请求进行报警

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
---
- hosts: tengine
remote_user: root
tasks:
- name: Rsync tengine config
synchronize: src=/root/tengine-inte-conf/inte-conf/{{ ansible_host }}/ dest=/opt/tengine/conf/conf.d/ delete=yes compress=yes

- name: Test tengine config
command: /opt/tengine/sbin/nginx -t
register: result
ignore_errors: true

- name: Reload config
command: /opt/tengine/sbin/nginx -s reload
when: result is not failed

- name: Send Alert
command: curl -H "Content-Type:application/json" -X POST -d "{'app':'e7775bf8-3855-509d-d924-7c7e3efd7df0','eventId':'88888','eventType':'trigger','alarmName':'TengineConfError','entityName':'{{ ansible_host }}-tengineconf','entityId':'88888','alarmContent':'{{ ansible_host }}-tengineconf','priority':'2'}" http://api.onealert.com/alert/api/event/zabbix/v3
when: result is failed

实例二

直接发送post请求进行报警

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
- hosts: tengine
remote_user: root
tasks:
- name: Rsync tengine config
synchronize: src=/root/tengine-inte-conf/inte-conf/{{ ansible_host }}/ dest=/opt/tengine/conf/conf.d/ delete=yes compress=yes

- name: Test tengine config
command: /opt/tengine/sbin/nginx -t
register: result
ignore_errors: true

- name: Reload config
command: /opt/tengine/sbin/nginx -s reload
when: result is not failed

- name: Send Alert
uri:
url: http://api.onealert.com/alert/api/event/zabbix/v3
method: POST
body: "{'app':'e7775bf8-3855-509d-d924-7c7e3efd7df0','eventId':'88888','eventType':'trigger','alarmName':'TengineConfError','entityName':'{{ ansible_host }}-tengineconf','entityId':'88888','alarmContent':'{{ ansible_host }}-tengineconf','priority':'2'}"
body_format: json
force_basic_auth: no
headers:
Content-Type: "application/json"
when: result is failed
-------------本文结束感谢您的阅读-------------

本文标题:ansible实例

文章作者:豌豆多多

发布时间:2020年07月13日 - 16:07

最后更新:2020年07月13日 - 17:07

原始链接:https://wandouduoduo.github.io/articles/1d90220.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

原创技术分享,您的支持将鼓励我继续创作