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] Sử dụng điều kiện trong jinja2 template


Để sử dụng các câu lệnh điều kiện trong jinja2 template của Ansible, bạn có thể sử dụng cấu trúc if-else. Ví dụ:

{{ if variable == "value" }}
    This is true.
{{ else }}
    This is false.
{{ endif }}

Trong đó, variable là biến mà bạn muốn kiểm tra và "value" là giá trị mà bạn muốn so sánh với biến đó. Nếu biến bằng giá trị này thì sẽ được in ra câu "This is true.", nếu không thì sẽ in ra câu "This is false.".

Bạn cũng có thể sử dụng các toán tử so sánh khác như !=, <, >, <=, >= để kiểm tra giá trị của biến.