Ansible是一種用于自動(dòng)化任務(wù)的開(kāi)源工具。它管理Linux和Windows服務(wù)器的配置。它在沒(méi)有代理的情況下工作,這意味著Ansible使用SSH和當(dāng)前用戶(hù)SSH授權(quán)。
你可以使用Ansible自動(dòng)化三種類(lèi)型的任務(wù):
配置:在基礎(chǔ)設(shè)施中設(shè)置幾個(gè)需要的服務(wù)器。
配置管理:更改應(yīng)用程序、操作系統(tǒng)或設(shè)備的配置;啟動(dòng)和停止服務(wù);安裝或更新應(yīng)用程式;實(shí)現(xiàn)安全策略或執(zhí)行各種其他配置任務(wù)。
應(yīng)用程序部署:通過(guò)將內(nèi)部開(kāi)發(fā)的應(yīng)用程序的部署自動(dòng)化到生產(chǎn)系統(tǒng),使DevOps更容易。
本文將指導(dǎo)您完成CentOS 7上Ansible的安裝和安裝過(guò)程,以及在Windows服務(wù)器上運(yùn)行的計(jì)算機(jī)的管理配置。
先決條件
sudo用戶(hù)。
CentOS 7服務(wù)器實(shí)例。
安裝
添加EPEL存儲(chǔ)庫(kù)。
sudo yum install epel-release
更新包。
sudo yum -y update
一旦包被更新,用yum安裝Ansible。
sudo yum -y install ansible
要管理您的Windows服務(wù)器,您需要安裝以下軟件包:
安裝Python包。
sudo yum -y install python-pip pip
安裝WinRM (Windows遠(yuǎn)程管理)。
pip install pywinrm
通過(guò)使用以下命令檢索其版本來(lái)測(cè)試Ansible安裝。
ansible --version
ansible 2.5.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
配置Ansible用于Windows服務(wù)器管理
去Ansible目錄。
cd /etc/ansible
使用您最喜歡的文本編輯器編輯hosts文件。
nano hosts
在windows組的底部添加以下代碼行。
[windows]
server1.domain.local
server1.domain.local
有必要?jiǎng)?chuàng)建一個(gè)加密的保險(xiǎn)庫(kù),其中包含Windows服務(wù)器的訪(fǎng)問(wèn)標(biāo)識(shí)符。為此,我們將創(chuàng)建一個(gè)新的加密yml文件。文件名必須與應(yīng)用它的主機(jī)組匹配。在我們的示例中,創(chuàng)建的組稱(chēng)為windows,因此文件將是windows.yml。
mkdir group_vars
cd group_vars
ansible-vault create windows.yml
在您的yml文件中,添加以下參數(shù)。
ansible_ssh_user: _your_ssh_user_
ansible_ssh_pass: _your_ssh_pass_
ansible_ssh_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
配置Windows服務(wù)器
可以使用PowerShell腳本自動(dòng)配置計(jì)算機(jī)。該腳本將自動(dòng)配置WinRM (Windows遠(yuǎn)程管理)并打開(kāi)防火墻。
從Github下載PowerShell腳本。
修改PowerShell腳本的執(zhí)行規(guī)則,以允許執(zhí)行腳本。
Set-ExecutionPolicy RemoteSigned
執(zhí)行該腳本。
.\ConfigureRemotingForAnsible.ps1
您的Windows服務(wù)器現(xiàn)在可以用Ansible進(jìn)行遠(yuǎn)程管理了。
文章轉(zhuǎn)載于:https://www.cnbanwagong.com/jiaocheng.html
聯(lián)系客服