ansible hosts配置,ansiblehosts
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_rsaansible_ssh_port=22ansible_ssh_user=root[t3:vars] # t3 使用python解譯器是python2ansible_python_interpreter=/usr/bin/python2nginx_port=80 # 私人變數在playbooks中使用[t3]192.168.11.162