離線環境安裝使用 Ansible

2022-09-10 16:18:26 字數 1675 閱讀 6935

之前寫了一篇介紹 ansible 的文章 ,今天回顧看來寫的有些匆忙,一些具體的操作步驟都沒有講明白,不利於讀者復現學習。最近又申請了乙個幾百台機器的環境,正好藉此機會把如何在離線環境中使用 ansible 詳細記錄一下。

本機環境是 python 2.7,作業系統版本是 red hat enterprise linux server release 7.6 (maipo)。

總結下來,必須使用本地 yum 源安裝幾個必須的依賴。

$ yum install -y python-devel openssl-devel gcc libffi-devel
ansible 安裝需要先將 18 個依賴包安裝完成,依賴包的安裝過程大同小異,都是解壓檔案後,通過python setup.py install命令進行安裝。

完成後,驗證安裝結果。推薦大家使用 github 上 ghl1024 整理的乙個安裝指令碼來自動化這個過程,如果需要特定的版本,自己修改指令碼內容就可以。

$ ansible --version
使用 ansible 操作目標主機的方式有兩種,一種是通過配置主機列表後在命令列中通過主機列表名稱選擇裝置。例如:

$ ansible machinelist -m command -a 'cat /etc/redhat-release'
這裡的 machinelist 對應 /etc/ansible/hosts 檔案中的一組機器列表

[machinelist]

10.2.1.1

10.2.1.2

使用這種方式配置的機器列表,需要安裝了 ansible 的這台機器與列表中的主機都做了 ssh 互信。

我們可以利用 sshpass 這個應用來實現使用使用者密碼登入,這種方式要求安裝了 ansible 的機器上先要安裝 sshpass 。在離線環境下,推薦大家通過 rpm 包進行安裝或者編譯安裝。

安裝完成後,修改 hosts 檔案配置如下。

[machinelist]

10.2.1.1 ansible_ssh_user=root ansible_ssh_pass=******

10.2.1.2 ansible_ssh_user=root ansible_ssh_pass=******

兩種方式的配置可以混合使用。

在使用 ansible 向多台主機傳送命令的過程中,有些主機有以下的 warning 提示。

看文字的大意是某些機器上的 python 是在/usr/bin/python下的,未來可能會被替換。

忽略這個錯誤的辦法是在/etc/ansible/ansible.cfg中新增以下配置。

[defaults]

interpreter_python = auto_legacy_silent

ansible 離線安裝

ansible的安裝配置和配合sshpass的使用

sshpass 繞過ssh 密碼互動式驗證

ansible 實現批量建立互信

platform linux on host is using the discovered python interpreter

ansible 離線安裝

環境 centos7 yum y install downloadonly downloaddir tmp ans ansible 安裝createrepo命令 yum install createrepo 將該目錄製作成軟體倉庫 createrepo tmp ans 壓縮檔案 tar czvf a...

如何離線安裝ansible

在有網路的情況下,ansible還是很好安裝的。但如果你的生產環境有很嚴格的網路要求,不能夠連線外網,你又需要在生產環境上使用ansible。那只有使用離線的方式來安裝。但很可惜的是,ansible官方提供的安裝包,比如rpm包,並沒有包含它所需要的依賴,直接安裝是無法使用的。因此需要找個方法自己把...

centos7離線安裝ansible

centos7離線安裝ansible 2 啟動ssh服務。3 收集金鑰檔案。示例 ssh keygen t rsa p 寫入信任檔案 將 root ssh id rsa storm1.pub分發到其他伺服器,並在所有伺服器上執行如下指令 cat root ssh id rsa storm1.pub ...