Ubuntu批量安裝離線安裝python的pycrypto庫

衆所周知知,PyCrypto的庫安裝方法如下:
pip install pycrypto

因主機無法聯網,造成無法使用pip install 命令,於是選擇離線安裝pycrypto並庫。
結合ansible批量對離線主機安裝pycrypto庫

PyCrypto庫離線安裝包及依賴的源碼包下載鏈接

$sudo apt-get install -y python-dev

wget http://www.mpir.org/mpir-2.5.1.tar.bz2
wget http://ftp.gnu.org/pub/gnu/gmp/gmp-5.0.5.tar.bz2
wget https://files.pythonhosted.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz

使用ansible-playbook進行安裝
ansible-playbook install.yaml
install.yaml內容如下:

---
- hosts: ubuntu1204
  remote_user: root
    sudo: yes
    sudo_user: user
  serial: 7
  gather_facts: F
  tasks:
      - name: jianyan
        copy: src=/mnt/PyCrypto.tar.gz dest=/usr/local/src/
      - name: jianyan
        shell: python /usr/local/src/install.sh

安裝腳本install.sh如下:

#!/bin/bash
cd /usr/local/src/
tar -zxvf PyCrypto.tar.gz
cd /usr/local/src/PyCrypto/
bunzip2 gmp-5.0.5.tar.bz2
tar -xvf gmp-5.0.5.tar
cd gmp-5.0.5/
./configure
make
make check
make install

cd /usr/local/src/PyCrypto/
bunzip2 mpir-2.5.1.tar.bz2
tar -xvf mpir-2.5.1.tar
cd mpir-2.5.1/
./configure
make
make check
make install

cd /usr/local/src/PyCrypto/
tar -zxvf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1/
python setup.py build
python setup.py install

檢驗離線安裝PyCrypto庫是否成功

#!/bin/bash
#name = check.py
try:
    from Crypto.Signature import PKCS1_v1_5
    print "ok, install"
except ImportError:
    print "not found"

批量檢驗後執行結果如下:

$ ansible ubuntu1204 -m shell -a "python /usr/local/src/try.py" -u root
168.1.64 | SUCCESS | rc=0 >>
ok, install

168.1.68 | SUCCESS | rc=0 >>
ok, install

168.1.69 | SUCCESS | rc=0 >>
ok, install

168.1.70 | SUCCESS | rc=0 >>
ok, install

168.1.67 | SUCCESS | rc=0 >>
ok, install
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章