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] Lesson 10 – Kiểm soát thời gian chờ kết nối


Các module mạng có thể hỗ trợ nhiều giao thức kết nối, chẳng hạn như ansible.netcommon.network_cli, ansible.netcommon.netconf và ansible.netcommon.httpapi. Những kết nối này bao gồm một số tùy chọn thông thường bạn có thể đặt để kiểm soát cách kết nối với thiết bị mạng của bạn hoạt động.

Một số tùy chọn thông thường bao gồm:

  • become và become_method như đã mô tả trong Phương thức đặc quyền: chế độ kích hoạt, trở thành và ủy quyền.
  • network_os – được đặt để phù hợp với nền tảng mạng bạn đang giao tiếp. Xem các trang cụ thể của nền tảng.
  • remote_user như đã mô tả trong Thiết lập người dùng từ xa.
  • Các tùy chọn timeout – persistent_command_timeout, persistent_connect_timeout và timeout.

Setting timeout options

Khi giao tiếp với một thiết bị từ xa, bạn có thể kiểm soát thời gian Ansible duy trì kết nối với thiết bị đó, cũng như thời gian Ansible đợi một lệnh hoàn thành trên thiết bị đó. Mỗi tùy chọn này có thể được đặt làm biến trong các file playbook của bạn, biến môi trường hoặc các cài đặt trong file ansible.cfg của bạn.

Ví dụ, ba tùy chọn để kiểm soát thời gian chờ kết nối như sau:

Sử dụng vars (mỗi task):

- name: save running-config
  cisco.ios.ios_command:
    commands: copy running-config startup-config
    vars:
      ansible_command_timeout: 30

Sử dụng biến môi trường:

export ANSIBLE_PERSISTENT_COMMAND_TIMEOUT=30

Sử dụng cấu hình chung (trong ansible.cfg)

[persistent_connection]
command_timeout = 30