Ansible

  • 透過playbook可自動化執行重複的任務
  • 使用yaml格式
  • 會記錄操作歷程

名詞

playbook - 執行yaml檔案的內容

inventory - 節點清單 (執行任務的位置)

moudule - 可使用的模組,如:ping、yum

plugin - 連線至控制端的方式,如:SNMP

role - 包含多個moudule的工作指令,可使用ansible-galaxy的社群搜尋其他人製作的role

安裝ansible在rhel

$ yum install python3
$ pip3 install --upgrade pip
$ pip3 install ansible
$ ansible --version     #檢查

範例

環境簡介

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

$ ansible server -m ping -i  benson-inventory --ask-pass
### ansible <client端名稱或ip> -m <module> -i <inventory檔案名稱>
    --ask-pass:登入需要password
### 當ssh未提前交換key時,需要添加--ask-pass手動輸入密碼

$ ssh-keygen -t rsa -P ""        #產生公、私鑰
$ ls ~/.ssh
authorized_keys                  #記錄別台主機提供的公鑰,可無須密碼登入
id_rsa                           #私鑰
id_rsa.pub                       #公鑰
known_hosts                      #ssh登入過主機的公鑰都會記錄,提高安全性

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

$ ansible-playbook benson-test.yml -i benson-inventory --ask-pass
###使用playbook讓client端完成指定task

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Ansible Automation Platform(AAP)

$ automation-controller-service stop        #停止aap服務