1. 程式人生 > >ansible hosts配置

ansible hosts配置

python解釋器 連續 參數配置 hosts配置 title -m sudo 變量 inventory

  1. 編輯/etc/ansible/hosts
  2. 添加本機的public SSH key到目標機器的authorized_keys #ssh-copy-id
  3. 添加本機的私鑰到Ansible
  4. 運行ansible all -m ping 測試是否添加成功
Inventory 分組 Ansible可同時操作屬於一個組的多臺主機,組和主機之間的關系通過inventory文件配置,默認文件路徑為/etc/ansible/hosts 常用參數配置: ansible_ssh_host # 目標主機地址 ansible_ssh_port # 目標主機端口,默認22 ansible_ssh_user # 目標主機用戶 ansible_ssh_pass # 目標主機ssh密碼 ansible_sudo_pass # sudo密碼 ansible_sudo_exe ansible_connection # 與主機的連接類型,比如:local,ssh或者paramiko ansible_ssh_private_key_file # 私鑰地址 ansible_shell_type # 目標系統的shell類型 ansible_python_interpreter # python版本 格式:[組名]
例如 :   [test]   # 組名   10.0.0.1  # 主機ip 或者10.0.0.1:65522 自定義端口 別名 s1 ansible_ssh_port=65522 ansible_ssh_host=10.0.0.1 ansible_ssh_user=simon   # 別名s1 連續的主機   [g1]   g[1:50].example.com   g[a-f].example.com
[all:vars]         # *:vars 塊變量,all:vars 全局變量
ansible_ssh_private_key_file=/root/.ssh/id_rsa
ansible_ssh_port=22
ansible_ssh_user=root

[t3:vars]  # t3 使用python解釋器是python2
ansible_python_interpreter=/usr/bin/python2
nginx_port=80               # 私有變量在playbooks中使用

[t3]
192.168.11.162

ansible hosts配置