配置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扫一扫
-
- 我的头条
- 头条扫一扫
-
评论