Inventory
Inventory簡單來說就是你的伺服器清單,當中包括了伺服器位址和連接設定。
A fully-featured inventory file can serve as the source of truth for your network. Using an inventory file, a single playbook can maintain hundreds of network devices with a single command. This page shows you how to build an inventory file, step by step.
Ansible 2.8 Documentation
沒錯,只要你的Inventory file設定好,所有在Inventory中的伺服器都任你指揮!
基本的Inventory可以這樣設定:
Parameters
Description
Specification
ansible_connection
連接其他伺服器或本機的方式
ssh,winrm,local
ansible_port
連接伺服器的連接埠號碼
1-65536(default:22)
ansible_user
連接伺服器的用戶
username
ansible_ssh_paa
使用ssh連接伺服器時用戶的密碼
password
ansible_password
使用winrm連接伺服器時用戶的密碼
password
上面的例子指定了本機及另一台伺服器的設定,然後你就能使用playbook開始自動化你的工作了!
如果你有好多台伺服器,你亦可以做一份複雜的inventory來實現不同的群組設定。以下是一個例子:
這個例子中,webserver都是以Windows作為OS運作,而且都在web_nodes群組;資料庫則使用Linux系統,歸類在db_nodes。而它們亦有以地方作為類別分組,sql_db1及web_node1在boston_nodes中;其餘則在dallas_nodes當中,而最後的us_nodes就包括兩個地方的nodes,即是所有的伺服器都在us_nodes當中。
Last updated
Was this helpful?