Logo

Personal Ops Runbook

Personal runbook covering infrastructure operations for Cloud, Kubernetes, OpenStack, and Ceph environments. Includes deployment and teardown procedures, node management, cluster monitoring setup, and incident response workflows compiled from day-to-day operational work. Intended strictly for personal reference — configurations and scripts are environment-specific and not guaranteed to work as-is elsewhere.

[Ansible] Quản lý file bằng Ansible


Xoá file.

Để xoá một file trong Ansible, chúng ta có thể sử dụng module file với option state=absent. Ví dụ để xoá file /root/.ssh/id_rsa, ta có thể sử dụng playbook như sau:

- name: Remove id_rsa
  file:
    path: /root/.ssh/id_rsa
    state: absent

Trong đó:

  • name: tên của task.
  • file: tên của module sử dụng để thao tác với file.
  • path: đường dẫn tới file cần xoá.
  • state: trạng thái của file, ở đây là absent.

Lưu ý: để thực hiện được việc xoá file, user thực thi playbook cần phải có quyền để thực hiện thao tác này.