Ansible_Inventory

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_hosthost主機地址
ansible_porthost端口
ansible_user認證用戶
ansible_ssh_passssh_pwd 使用vault
ansible_ssh_private_key_filessh私鑰文件
ansible_sudo
ansible_sudo_pass
ansible_connectionhost連接方式
ansible_shell_type
ansible_python_interpreter
ansible_*_interpreter其他語言解析路徑

more_variables





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章