Skip to content

Ansible 自动化运维实战 ​

Ansible 作为无代理(Agentless)的自动化运维工具,凭借极简的 SSH 通信方式与强大的模块生态,成为本站管理数十台异构主机的核心工具。

1. Inventory 模块化设计 ​

在 clients/mycloud/inventory/hosts.yml 中:

yaml
all:
  hosts:
    lcl_hwcloud:
      ansible_host: 113.45.8.63
      ansible_user: root
      ansible_ssh_private_key_file: '{{ lookup("oracle_vault", "ssh/id_ed25519") }}'

    lcl_aliyun_swas:
      ansible_host: 47.93.9.163
      ansible_user: root
      ansible_ssh_private_key_file: '{{ lookup("oracle_vault", "ssh/id_ed25519") }}'

2. 常用管理指令 ​

bash
# 全局快速连通性探测
ansible -i clients/mycloud/inventory/hosts.yml all -m raw -a "uptime"

# 批量分发脚本或配置
ansible -i clients/mycloud/inventory/hosts.yml all -m copy -a "src=nginx.conf dest=/etc/nginx/nginx.conf"

老男孩爱学习 · 终身学习 · 技术沉淀 | 湘ICP备2026001031号-2