5、python自動化營運——集中化管理平台Ansible

來源:互聯網
上載者:User

標籤:python   Linux   Ansible   自動化營運   

集中化管理平台Ansible

簡介:Ansible是一種整合IT系統的組態管理、應用部署、執行特定任務的開源平台
特點:
1、部署簡單,只需在主控端部署Ansible環境,被控端不用進行任何操作
2、預設使用SSH協議對裝置進行管理
3、主從集中化管理
4、提供一個Web管理介面和RESET API介面——AWX平台

Ansible安裝及配置

1、安裝ansible:yum install –y ansible

2、修改設定檔:/etc/ansible/hosts,添加主機IP。

193.192.168.1.1[webservers]192.168.1.1

3、測試是否ping通:ansible 192.168.118.132 –m ping –k

4、設定通過密鑰無密碼登陸;主機控制端產生私密金鑰和公開金鑰;然後把公開金鑰複製到被控制端。

ssh-keygen  -t  rsassh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
Ansible常用模組及API1、遠程命令模組

功能:模組包括command,script,shell,可以遠程實現shell命令。
樣本:

ansible 192.168.1.1 -m command -a “free -m”ansible 192.168.1.1 -m script -a “/root/mbb.sh” #被控端執行主動的指令碼ansible 192.168.1.1 -m shell -a “/root/mbb.sh” #被控端執行被控端的指令碼
2、copy模組(相當於scp)

功能:主機端向被控端拷貝檔案
樣本:

ansible 192.168.1.1 –m copy –a “src=/root/mbb.txt dest=/root/” #把mbb.txt拷貝到被控端的root目錄下
3、stat模組

功能:擷取遠程檔案的狀態資訊
樣本:

ansible 192.168.1.1 –m stat –a “path=/root/reboot.bak”
4、get_url模組

功能:實現遠程下載制定URL到本地
樣本:

ansible 192.168.1.1 –m get_url –a “path=http://www.baidu.com dest=/tmp/index.html”
5、yum 模組(遠程yum安裝軟體)

功能:Linux軟體包管理,常見的有yum,apt方式
樣本:

ansible 192.168.1.1 –m yum –a “name=tcping state=latest”ansible 192.168.1.1 -m apt -a “pkg=tcping state=latest”
6、cron模組(制定定時計劃)

功能:遠程主機crontab配置
樣本:

ansible 192.168.1.1 -m cron -a "name=‘check dir‘ hour=‘5,2‘ job=‘ls /root > /root/dir.bak‘"
7、mount模組(遠程掛載)

功能:遠程主機分區掛載
樣本:

ansible 192.168.1.1 –m mount –a “name=/mnt/cdrom ”
8、service模組(啟動服務)

功能:遠程主機系統服務的管理
樣本:

ansible 192.168.1.1 -m service -a "name=nginx state=started"
Playbook(待完善,需結合實際)

Playbook不同於ansible命令列執行方式的模式,可以進行定製配置,通過yml格式來進行

執行playbook,ansible-playbook nginx.yml

5、python自動化營運——集中化管理平台Ansible

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.