ansible清理日志

IT
IT
IT
335
文章
1
评论
2020年3月22日22:22:22 评论 1,615 1853字阅读6分10秒

配置ymal

[xiaoxin@iZ2zee6df2m25shq6mfaw5Z ansible]$ vim log.ymal
---
- hosts: log
  tasks:
  - name: Create the code pull directory
    file:
      path: /home/xiaoxin/app/delete
      state: directory
      mode: '0755'
  - name: Synchronize and delete files in dest on the remote host that are not
    synchronize:
      src: /home/xiaoxin/ansible/log
      dest: /home/xiaoxin/app/delete
      delete: yes
      recursive: yes
  - name: clear rest log
    cron:
      name: clear rest log
      minute: '1'
      hour: '1'
      day: '7'
      month: '*'
      weekday: '*'
      job: "/bin/bash /home/xiaoxin/app/delete/log/{{ ansible_host }}.sh"
      state: present

脚本目录

[xiaoxin@iZ2zee6df2m25shq6mfaw5Z ansible]$ mkdir log
xiaoxin@iZ2zee6df2m25shq6mfaw5Z ansible]$ cd log
[xiaoxin@iZ2zee6df2m25shq6mfaw5Z log]$ ll
total 28
-rwxrwxr-x 1 xiaoxin xiaoxin  684 Oct 12 14:30 10.0.0.104.sh
-rwxrwxr-x 1 xiaoxin xiaoxin  912 Oct 12 14:24 10.0.0.105.sh
-rwxrwxr-x 1 xiaoxin xiaoxin  569 Oct 12 16:29 10.0.0.113.sh
-rwxrwxr-x 1 xiaoxin xiaoxin  687 Oct 12 16:32 10.0.0.114.sh
-rwxrwxr-x 1 xiaoxin xiaoxin  299 Oct 12 16:34 10.0.0.115.sh
-rwxrwxr-x 1 xiaoxin xiaoxin  477 Oct 12 17:13 10.0.0.91.sh
-rwxrwxr-x 1 xiaoxin xiaoxin 1117 Oct 12 16:43 10.0.0.93.sh
[xiaoxin@iZ2zee6df2m25shq6mfaw5Z log]$ vim 10.0.0.104.sh
#!/bin/bash
#######删除指定服务器所有应用7天前的日志####
################勿动配置文件################
#######为了防止勿删除,写的绝对路径#########
set -e
product=(
"/home/xiaoxin/app/task-starter-1.0-SNAPSHOT/log/task-center/dao"
"/home/xiaoxin/app/task-starter-1.0-SNAPSHOT/log/task-center/elk"
"/home/xiaoxin/app/task-starter-1.0-SNAPSHOT/log/task-center/error"
"/home/xiaoxin/app/task-starter-1.0-SNAPSHOT/log/task-center/info"
"/home/xiaoxin/app/trade-starter-1.0-SNAPSHOT/LOG_PATH_IS_UNDEFINED"
"/home/xiaoxin/app/user-starter-1.0-SNAPSHOT/LOG_PATH_IS_UNDEFINED"
)
for d in ${product[*]}
do
  find $d -mtime +7 -type f -exec rm -rf {} \;
  done

主机组配置

[xiaoxin@iZ2zed99h19kmb7fgbjcghZ ~]$ vim /etc/ansible/hosts
[log]
10.0.0.104
10.0.0.105
10.0.0.113
10.0.0.114
10.0.0.115
10.0.0.91
10.0.0.93

执行

[xiaoxin@iZ2zed99h19kmb7fgbjcghZ ansible]$ ansible-playbook log.ymal --extra-vars "ansible_ssh_user=root"
继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2020年3月22日22:22:22
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
ansible检查服务状态 Ansible

ansible检查服务状态

检查返回状态是否200,非200中断执行 --- - name: Get Service status hosts: all tasks: - name: Get Service status uri...
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...