python自動化之Ansible的安裝教程
本文實(shí)例講述了python自動化之Ansible的安裝。分享給大家供大家參考,具體如下:
一 點(diǎn)睛
Ansible只需在管理端部署環(huán)境即可,建議采用yum
源方式來實(shí)現(xiàn)部署。
二 安裝Ansible
只需要在主服務(wù)器安裝(主控端)
[root@localhost dev]# yum install ansible -y
三 測試
1 修改在主控機(jī)配置文件/etc/ansible/hosts
## green.example.com ## blue.example.com 192.168.0.101 192.168.0.102 [webservers] ## alpha.example.org ## beta.example.org 192.168.0.101 192.168.0.102
2 執(zhí)行下面操作
通過ping模塊測試主機(jī)的連通性,分別對單主機(jī)及組進(jìn)行ping操 作,結(jié)果如下,說明安裝、測試成功。
[root@localhost ansible]# ansible 192.168.0.101 -m ping -k SSH password: 192.168.0.101 | SUCCESS => { "changed": false, "ping": "pong" } [root@localhost ansible]# ansible webservers -m ping -k SSH password: 192.168.0.102 | FAILED! => { "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host." } 192.168.0.101 | SUCCESS => { "changed": false, "ping": "pong" }
3 說明
由于主控端與被控主機(jī)未配置SSH證書信任,需要在執(zhí)行ansible命令時添加-k參數(shù),要求提供root(默認(rèn))賬號密碼,即在提示“SSH password:”時輸入。
四 配置Linux主機(jī)SSH無密碼訪問
1 點(diǎn)睛
為了避免Ansible下發(fā)指令時輸入目標(biāo)主機(jī)密碼,通過證書簽名達(dá)到SSH無密碼是一個好的方案,推薦使用ssh-keygen與ssh-copy-id來實(shí)現(xiàn)快速證書的生成及公鑰下發(fā),其中ssh-keygen生成一對密鑰,使用sshcopy-id來下發(fā)生成的公鑰。
第一步:需要配置與目標(biāo)設(shè)備的密鑰認(rèn)證支持。
[root@localhost home]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:9/pGNxnQVWAWpss7PYtJcUDyHsCexgYY6NGWy/oOhTg root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ | o.+ .o ..*++| | o = . .=.=. | | . + . + .=. | | ...o *o +. | | E ... So. = .o | | ... . ..=+ | | .. .=.o. | | .. o.+ o | | .. .o+ . | +----[SHA256]-----+
私鑰文件可以存放在默認(rèn)路徑“~/.ssh/id_rsa”。
第二步:接下來同步公鑰文件id_rsa.pub到目標(biāo)主機(jī),推薦使用ssh-copy-id公鑰拷貝工具
[root@localhost ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.0.102 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys Kernel \r on an \m root@192.168.0.102's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.0.102'" and check to make sure that only the key(s) you wanted were added.
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
VSCode配合pipenv搞定虛擬環(huán)境的實(shí)現(xiàn)方法
這篇文章主要介紹了VSCode配合pipenv搞定虛擬環(huán)境的實(shí)現(xiàn)方法,文中通過圖文教程介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05Pycharm導(dǎo)入anaconda環(huán)境的教程圖解
這篇文章主要介紹了Pycharm導(dǎo)入anaconda環(huán)境的教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07pycharm?使用conda虛擬環(huán)境的詳細(xì)配置過程
這篇文章主要介紹了pycharm?使用conda虛擬環(huán)境,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03淺談Python類里的__init__方法函數(shù),Python類的構(gòu)造函數(shù)
下面小編就為大家?guī)硪黄獪\談Python類里的__init__方法函數(shù),Python類的構(gòu)造函數(shù)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12解決pycharm py文件運(yùn)行后停止按鈕變成了灰色的問題
今天小編就為大家分享一篇解決pycharm py文件運(yùn)行后停止按鈕變成了灰色的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11