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"

编写批处理py_module.yml文件

---
- hosts: pro_py
  remote_user: root
  serial: 7
  gather_facts: F
  tasks:
      - name: show
        copy: src=/home/mengix/try.py dest=/usr/locar/src/try.py owner=root group=root mode=0644
      - name: jianyan
        shell: python /usr/locar/src/try.py

批量检验后执行结果如下:

$ ansible-playbook py_module.yml 

PLAY [pro_py] ******************************************************************

TASK [jianyan] *****************************************************************
changed: [192.168.1.73]
changed: [192.168.1.4]
changed: [192.168.1.6]
changed: [192.168.1.7]
changed: [192.168.1.69]
changed: [192.168.1.72]
changed: [192.168.1.66]

TASK [show] ********************************************************************
ok: [192.168.1.69] => {
    "check.stdout": "ok, install"
}
ok: [192.168.1.72] => {
    "check.stdout": "ok, install"
}
ok: [192.168.1.73] => {
    "check.stdout": "ok, install"
}
ok: [192.168.1.7] => {
    "check.stdout": "ok, install"
}
ok: [192.168.1.66] => {
    "check.stdout": "ok, install"
}
ok: [192.168.1.4] => {
    "check.stdout": "ok, install"
}
ok: [192.168.1.6] => {
    "check.stdout": "ok, install"
}

PLAY RECAP *********************************************************************
192.168.1.66             : ok=2    changed=1    unreachable=0    failed=0   
192.168.1.69             : ok=2    changed=1    unreachable=0    failed=0   
192.168.1.7               : ok=2    changed=1    unreachable=0    failed=0   
192.168.1.72             : ok=2    changed=1    unreachable=0    failed=0   
192.168.1.73             : ok=2    changed=1    unreachable=0    failed=0   
192.168.1.4               : ok=2    changed=1    unreachable=0    failed=0   
192.168.1.6               : ok=2    changed=1    unreachable=0    failed=0

转载于:https://blog.51cto.com/mengix/2386249

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值