Ansible_Inventory
管理被控端主機表;
默認讀取/etc/ansible/hosts;
可通過 ansible -i 指定hosts文件;
1.定義主機和組
$ cat /etc/ansible/hosts # “client_105”:主機別名 client_105 ansible_connection=ssh ansible_ssh_port=22 ansible_ssh_host=192.168.38.105 ansible_ssh_user=root192.168.38.105 ansible_ssh_pass='123456'192.168.38.106 ansible_ssh_pass='123456'[docker]192.168.38.10[5:6] # 定義組變量 [docker:vars] ansible_pass='123456'# 定義ansible組,組內包括docker子組 [ansible:children] docker
2. 多個Inventory列表
* 修改ansible.conf: inventory = /etc/ansible/inventory/(爲目錄) * 定義目錄下不同hosts
3. 動態Inventory
inventory = 一個腳本(支持--list/--host參數)
分別返回host列表 和 host信息
編寫python腳本
4.Inventory參數列表
參數 | 解釋 |
---|---|
ansible_host | host主機地址 |
ansible_port | host端口 |
ansible_user | 認證用戶 |
ansible_ssh_pass | ssh_pwd 使用vault |
ansible_ssh_private_key_file | ssh私鑰文件 |
ansible_sudo | |
ansible_sudo_pass | |
ansible_connection | host連接方式 |
ansible_shell_type | |
ansible_python_interpreter | |
ansible_*_interpreter | 其他語言解析路徑 |