繁体   English   中英

如何验证 ansible playbook 删除了文件?

[英]How do I verify ansible playbook deleted a file?

所以我有一个删除文件的 ansible 剧本。

---
- hosts: localhost
  become: true
  tasks:
    - name: Copy file with owner and permissions
      file:
        path: /etc/logrotate.d/logrotate_file
        state: absent

如何验证删除确实是使用另一个剧本发生的?

所以我所做的是使用 stat ansible 模块来捕获和注册结果,然后使用调试模块来报告消息。

请注意,如果我们使用 assert 模块,这实际上可以做得更好。

---
- hosts: localhost
  become: true
  tasks:
    - name: register the value
      stat:
        path: /etc/logrotate.d/logrotate_file
      register: __sur_logfile


    - name: Message when it is True
      debug:
        msg: "The suricata Logrotate job is set up"
      when: __sur_logfile.stat.exists == true



    - name: Message when file does not exist (when values is false)
      debug:
        msg: "the job is not there"
      when: __sur_logfile.stat.exists == false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM