ドルヲタ系インフラエンジニア じーふーの備忘録

クラウドをメインに扱うインフラエンジニアが書くメモやら雑感、たまにドルヲタ的活動記録残します。最近の推しはAzureのData Factory(V2)です。

【Python / Ansible】 Ansible実行時、pycryptoのバージョンによりAttributeError

pycrypto(バージョン2.4以上)をインストールしている状態でansibleを実行すると、下記エラーが出るみたい?
pycrypto 2.3 をインストールすると正常に動作することを確認し、2.4、2.6.1(執筆時点での最新バージョン)インストール状態で動作確認した際はエラーとなりました。

[vagrant@vagrant-centos65 ~]$ ansible all -i 'localhost,' -c local -m ping
Traceback (most recent call last):
  File "/usr/bin/ansible", line 36, in <module>
    from ansible.runner import Runner
  File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 62, in <module>
    from Crypto.Random import atfork
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
    from Crypto.Random import _UserFriendlyRNG
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
    from Crypto.Random.Fortuna import FortunaAccumulator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
    import FortunaGenerator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
    from Crypto.Util.number import ceil_shift, exact_log2, exact_div
  File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
    if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'

追記(2015/04/30)

下記issue内にてエラー発生源の処理をコメントアウトする方法で対応した方もいましたので、そちらも紹介致します。
※紹介先サイトで対応した方も、正しい対応かはわからないけど...と言っていますので、こちらの対応が正かどうかは自信ありません。申し訳ございません
下記対応を入れた状態で、pycryptoのバージョンを2.4以上のものにアップデートして、正常に動作することを確認しました。

github.com

/usr/lib64/python2.6/site-packages/Crypto/Util/number.pyの下記処理(56~57行目)をコメントアウト

  55 # You need libgmp v5 or later to get mpz_powm_sec.  Warn if it's not available.
  56 if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
  57     _warn("Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing a     ttack vulnerability.", PowmInsecureWarning)

  55 # You need libgmp v5 or later to get mpz_powm_sec.  Warn if it's not available.
  56 #if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
  57 #    _warn("Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing a     ttack vulnerability.", PowmInsecureWarning)

追記ここまで


環境

  • CentOS 6.5(64bit)
  • ansible 1.9.0.1

実行ログ

[vagrant@vagrant-centos65 ~]$ sudo pip install pycrypto==2.6.1
Collecting pycrypto==2.6.1
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached pycrypto-2.6.1.tar.gz
Installing collected packages: pycrypto
  Running setup.py install for pycrypto
Successfully installed pycrypto-2.6.1
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$ ansible all -i 'localhost,' -c local -m ping
Traceback (most recent call last):
  File "/usr/bin/ansible", line 36, in <module>
    from ansible.runner import Runner
  File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 62, in <module>
    from Crypto.Random import atfork
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
    from Crypto.Random import _UserFriendlyRNG
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
    from Crypto.Random.Fortuna import FortunaAccumulator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
    import FortunaGenerator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
    from Crypto.Util.number import ceil_shift, exact_log2, exact_div
  File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
    if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$ sudo pip uninstall pycrypto

~省略~

[vagrant@vagrant-centos65 ~]$ sudo pip install pycrypto==2.4
Collecting pycrypto==2.4
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pycrypto-2.4.tar.gz (382kB)
    100% |????????????????????????????????| 385kB 178kB/s
Installing collected packages: pycrypto
  Running setup.py install for pycrypto
Successfully installed pycrypto-2.4
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$ ansible all -i 'localhost,' -c local -m ping
Traceback (most recent call last):
  File "/usr/bin/ansible", line 36, in <module>
    from ansible.runner import Runner
  File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 62, in <module>
    from Crypto.Random import atfork
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
    from Crypto.Random import _UserFriendlyRNG
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
    from Crypto.Random.Fortuna import FortunaAccumulator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
    import FortunaGenerator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
    from Crypto.Util.number import ceil_shift, exact_log2, exact_div
  File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
    if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
[vagrant@vagrant-centos65 ~]$ sudo pip uninstall pycrypto

~省略~

[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$ sudo pip install pycrypto==2.3
Collecting pycrypto==2.3
  Using cached pycrypto-2.3.tar.gz
Installing collected packages: pycrypto
  Running setup.py install for pycrypto
Successfully installed pycrypto-2.3
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$
[vagrant@vagrant-centos65 ~]$ ansible all -i 'localhost,' -c local -m ping
localhost | success >> {
    "changed": false,
    "ping": "pong"
}

[vagrant@vagrant-centos65 ~]$