ansible检查服务状态

IT
IT
IT
336
文章
1
评论
2020年5月22日20:07:50 评论 4,114 3638字阅读12分7秒

检查返回状态是否200,非200中断执行

---
- name: Get Service status
  hosts: all
  tasks:
    - name: Get Service status 
      uri:
        url: "http://baidu.com/"
        follow_redirects: none
        method: GET
      register: _result
      until: _result.status == 200
      retries: 3
      delay: 3

原文地址 https://www.jianshu.com/p/34f981b5f948

  • 结合自己所用服务
---
- hosts: app
tasks:
- name: Close service
shell: nohup /home/xiaoxin/app/register-center-web/bin/spcserv.sh stop
ignore_errors: true
- name: Please wait while the service is closed.
shell: sleep 15
- name: Create the code pull directory
file:
path: /home/xiaoxin/app/develop
state: directory
mode: '0755'
- name: Except target source
file:
path: /home/xiaoxin/app/register-center-web/lib
state: absent
- name: Delete target source
file:
path: /home/xiaoxin/app/register-center-web/conf
state: absent
- name: Delete the log three days ago
shell: find /home/xiaoxin/app/develop/ -mtime +3 -delete
- name: Copy the package configuration file
copy: src=/var/lib/jenkins/workspace/register-center/register-center-web/target/register-center-web.tar.gz dest=/home/xiaoxin/app/develop/
- name: A mobile application
shell: scp /home/xiaoxin/app/develop/register-center-web.tar.gz /home/xiaoxin/app/
- name: Push register-center-web.tar.gz
unarchive: src=/home/xiaoxin/app/register-center-web.tar.gz dest=/home/xiaoxin/app copy=no
- name: Remove the tag package
file:
path: /home/xiaoxin/app/register-center-web.tar.gz
state: absent
- name: Rename the new backup
shell: mv /home/xiaoxin/app/develop/register-center-web.tar.gz /home/xiaoxin/app/develop/register-center-web$(date +%Y%m%d%H%M%S).tar.gz
- name: Ansible delete file example
file:
path: /home/xiaoxin/app/develop/register-center-web.tar.gz
state: absent
- name: Copy start parameter
copy: src=/home/xiaoxin/catalina.sh dest=/home/xiaoxin/app/register-center-web/bin/
- name: Start the service
shell: nohup /home/xiaoxin/app/register-center-web/bin/spcserv.sh start
- name: Please wait while the service starts.
shell: sleep 10
- name: Get Service status
uri:
url: "http://127.0.0.1:8001"
follow_redirects: none
method: GET
register: _result
until: _result.status == 200
retries: 3
delay: 3
- hosts: app
tasks:
- name: Close service
shell: nohup /home/xiaoxin/app/register-center-web/bin/spcserv.sh stop
ignore_errors: true
- name: Please wait while the service is closed.
shell: sleep 15
- name: Create the code pull directory
file:
path: /home/xiaoxin/app/develop
state: directory
mode: '0755'
- name: Except target source
file:
path: /home/xiaoxin/app/register-center-web/lib
state: absent
- name: Delete target source
file:
path: /home/xiaoxin/app/register-center-web/conf
state: absent
- name: Delete the log three days ago
shell: find /home/xiaoxin/app/develop/ -mtime +3 -delete
- name: Copy the package configuration file
copy: src=/var/lib/jenkins/workspace/register-center/register-center-web/target/register-center-web.tar.gz dest=/home/xiaoxin/app/develop/
- name: A mobile application
shell: scp /home/xiaoxin/app/develop/register-center-web.tar.gz /home/xiaoxin/app/
- name: Push register-center-web.tar.gz
unarchive: src=/home/xiaoxin/app/register-center-web.tar.gz dest=/home/xiaoxin/app copy=no
- name: Remove the tag package
file:
path: /home/xiaoxin/app/register-center-web.tar.gz
state: absent
- name: Rename the new backup
shell: mv /home/xiaoxin/app/develop/register-center-web.tar.gz /home/xiaoxin/app/develop/register-center-web$(date +%Y%m%d%H%M%S).tar.gz
- name: Ansible delete file example
file:
path: /home/xiaoxin/app/develop/register-center-web.tar.gz
state: absent
- name: Copy start parameter
copy: src=/home/xiaoxin/catalina.sh dest=/home/xiaoxin/app/register-center-web/bin/
- name: Start the service
shell: nohup /home/xiaoxin/app/register-center-web/bin/spcserv.sh start
- name: Please wait while the service starts.
shell: sleep 10
- name: Get Service status
uri:
url: "http://127.0.0.1:8001"
follow_redirects: none
method: GET
register: _result
until: _result.status == 200
retries: 3
delay: 3
- name: Rename the new backup
shell: touch /home/xiaoxin/3.txt
  

[登录]

deploy.ymal

[/登录]

继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2020年5月22日20:07:50
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Ansible-Tower使用文档 Ansible

Ansible-Tower使用文档

导航栏介绍 # viewes Dashboard 仪表盘展示信息的 Jobs 跑过的任务记录 Schedules 计划任务 My View 查看用户的工作模版,和任务记录 # resources Te...
Ansible-Tower3.5破解 Ansible

Ansible-Tower3.5破解

Ansible-Tower不破解只能使用10台机器 需要注意:发现最新版本或者高版本的ansible-tower没有__init__.py文件,需要对__init__.pyc进行反编译,然后进行HOS...
Ansible-Tower3.5安装 Ansible

Ansible-Tower3.5安装

Ansible Tower架构 Ansible本质上是一个进行了封装的Shell。优点在于它是去中心化的工具,可以直接通过ssh管理远程主机,实现无Agent的部署(ssh+python环境已经原生集...