ansible playbook使用

执行远程脚本,然后下载下来

---
- hosts: mysql                              #mysql分组
  remote_user: root                         #执行的用户
  gather_facts: true
  tasks:
   - name: run shell                        #脚本执行任务
     shell: sh /root/daily_check.sh 
   - name: find file                        #查找脚本执行后的文件
     find:
       paths: /tmp/
       pattern: "*.tar.gz"
       recurse: no
     register: file_2_fetch                 #注册到一个变量,用于下载遍历
     
   - name: fetch file
     fetch: 
       src: "{{item.path}}"
       dest: ./{{ansible_all_ipv4_addresses[0]}}/  #下载到本地的一个目录,直接用对应服务器的ip地址做为目录
       flat: yes
     with_items: "{{ file_2_fetch.files }}"        
   
   - name: find files to rm
     shell: ls /tmp/|grep somepattern       # 目录下有同名的目录和压缩包,都获取到,然后删除
     register: file_2_rm                    #类似于上面

   - name: files to rm
     file: path=/tmp/{{ item }} state=absent  
     with_items: "{{file_2_rm.stdout_lines}}"

  

上一篇:OSCP Security Technology - Network Scanning(2)


下一篇:OSCP Security Technology - Gaining Root with Metasploit