前言
安裝完Ansible後還要進行基礎的設定之後才能使用
Basic Configuration
SSH key preparation
基本上雖然可以用--ask-pass指令輸入密碼來操作,但是實際上還是有ssh key比較簡單,詳細的部份就放在SSH Commands | Kiwi's Wiki
/etc/ansible/ansible.cfg
在範例中可以用
1 | ansible-config init --disable-all > /etc/ansible/ansible.cfg |
來建立一個預設全部都關掉的cfg檔,又或是直接手動建立如下
1 | #/etc/ansible/ansible.cfg |
基本上可以在hosts裡面針對不同的host(或是host group)進行設定,所以不一定需要在ansible.cfg內去設定remote_user或是private_key_file, 但是需要設定inventory位置
hosts
參考資料
Ansible official document - How to build Inventory
基本語法
1 | [tag1] |
上述的意思為有四個tag,一個是tag1有一台server1, tag2有一台server2,tag3有servera.example.com,serverb.example.com...serverz.example.com等26台server.tag4是ip表示的server
群組 :children
1 | [group1:children] |
有一個群組裡面包括了tag1&tag2,這個指令可以群組裡面包含群組弄成很多層
變數 :vars
1 | [group1:children] |
這裡設定了單項變數ansible_user=myuser在server1以及整體變數ansible_passwd=mypassword給tag3所有的機器上
參考範例
1 | # 設定localhost給在Localhost上使用的,主要是ansible-pull這種需要設定本機才需要 |
基本上hosts或該說inventory設定對於ansible來說是非常重要的定義,因為這個檔案基本上定義了你所有需要被納管的remote node資訊所以不要沒事把連同這個檔案在內的ansible設定放在public accessable repo內