オフライン環境にpywinrmをインストールする


はじめに

オフライン環境でAnsibleを実行することは十二分に考えられます。
その中で、AnsibleからWindowsに対して操作を行おう!とした場合は大抵pywinrmの導入が必要となります。

今回はオフライン環境にpywinrmを導入する方法を記載致します。

構成情報

バージョン
OS RHEL 7.6
Ansible 2.7.4
Python 2.7.5

pywinrm導入方法

pywinrmを導入するには、whl形式のpywinrmをインストールしてインストールします。
whlファイルのインストールコマンドは pip install xxx.whl です。
通常のRHELやCentOSにはpipは導入されていないため、まずはpipを導入します。

pip導入

pipはこのサイトにてtar.gz形式で配布されています。
今回は10.0.1をダウンロードします。

入手後以下コマンドを実行します。

# pipのtar.gzファイルが存在しているパスにて実行
[root@localhost ~]# easy_install pip-10.0.1.tar.gz
Processing pip-10.0.1.tar.gz
Writing /tmp/easy_install-fDqaZi/pip-10.0.1/setup.cfg
Running pip-10.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-fDqaZi/pip-10.0.1/egg-dist-tmp-Pw9xSG
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'src/pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching '*-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
warning: no previously-included files found matching 'src/pip/_vendor/six'
warning: no previously-included files matching '*.pyi' found under directory 'src/pip/_vendor'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/build'
no previously-included directories found matching 'news'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 10.0.1 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2.7 script to /usr/bin
Installing pip2 script to /usr/bin

Installed /usr/lib/python2.7/site-packages/pip-10.0.1-py2.7.egg
Processing dependencies for pip==10.0.1
Finished processing dependencies for pip==10.0.1
[root@localhost ~]# pip --version
pip 10.0.1 from /usr/lib/python2.7/site-packages/pip-10.0.1-py2.7.egg/pip (python 2.7)
[root@localhost ~]#

pywinrmの依存ファイルダウンロード

pywinrmをインストールします。
pywinrmインストール時には以下ファイルの事前インストールが必要となります。

インストールの順番は記載通りにしていきます。

[root@localhost ~]# pip install wheel-0.29.0-py2.py3-none-any.whl
Processing ./wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.29.0
[root@localhost ~]# pip install xmltodict-0.11.0-py2.py3-none-any.whl
Processing ./xmltodict-0.11.0-py2.py3-none-any.whl
Installing collected packages: xmltodict
Successfully installed xmltodict-0.11.0
[root@localhost ~]# pip install ntlm_auth-1.2.0-py2.py3-none-any.whl
Processing ./ntlm_auth-1.2.0-py2.py3-none-any.whl
Installing collected packages: ntlm-auth
Successfully installed ntlm-auth-1.2.0
[root@localhost ~]# pip install requests-2.9.1-py2.py3-none-any.whl
Processing ./requests-2.9.1-py2.py3-none-any.whl
Installing collected packages: requests
Successfully installed requests-2.9.1
[root@localhost ~]# pip install requests_ntlm-1.1.0-py2.py3-none-any.whl
Processing ./requests_ntlm-1.1.0-py2.py3-none-any.whl
Requirement already satisfied: ntlm-auth>=1.0.2 in /usr/lib/python2.7/site-packages (from requests-ntlm==1.1.0) (1.2.0)
Requirement already satisfied: cryptography>=1.3 in /usr/lib64/python2.7/site-packages (from requests-ntlm==1.1.0) (1.7.2)
Requirement already satisfied: requests>=2.0.0 in /usr/lib/python2.7/site-packages (from requests-ntlm==1.1.0) (2.9.1)
Requirement already satisfied: idna>=2.0 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (2.4)
Requirement already satisfied: pyasn1>=0.1.8 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (0.1.9)
Requirement already satisfied: six>=1.4.1 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (1.9.0)
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (0.9.8)
Requirement already satisfied: enum34 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (1.0.4)
Requirement already satisfied: ipaddress in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (1.0.16)
Requirement already satisfied: cffi>=1.4.1 in /usr/lib64/python2.7/site-packages (from cryptography>=1.3->requests-ntlm==1.1.0) (1.6.0)
Requirement already satisfied: pycparser in /usr/lib/python2.7/site-packages (from cffi>=1.4.1->cryptography>=1.3->requests-ntlm==1.1.0) (2.14)
Installing collected packages: requests-ntlm
Successfully installed requests-ntlm-1.1.0
[root@localhost ~]#

pywinrmインストール

最後にpywinrmをインストールします。


[root@localhost ~]# pip install pywinrm-0.2.2-py2.py3-none-any.whl
Processing ./pywinrm-0.2.2-py2.py3-none-any.whl
Requirement already satisfied: xmltodict in /usr/lib/python2.7/site-packages (from pywinrm==0.2.2) (0.11.0)
Requirement already satisfied: requests>=2.9.1 in /usr/lib/python2.7/site-packages (from pywinrm==0.2.2) (2.9.1)
Requirement already satisfied: requests-ntlm>=0.3.0 in /usr/lib/python2.7/site-packages (from pywinrm==0.2.2) (1.1.0)
Requirement already satisfied: six in /usr/lib/python2.7/site-packages (from pywinrm==0.2.2) (1.9.0)
Requirement already satisfied: ntlm-auth>=1.0.2 in /usr/lib/python2.7/site-packages (from requests-ntlm>=0.3.0->pywinrm==0.2.2) (1.2.0)
Requirement already satisfied: cryptography>=1.3 in /usr/lib64/python2.7/site-packages (from requests-ntlm>=0.3.0->pywinrm==0.2.2) (1.7.2)
Requirement already satisfied: idna>=2.0 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (2.4)
Requirement already satisfied: pyasn1>=0.1.8 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (0.1.9)
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (0.9.8)
Requirement already satisfied: enum34 in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (1.0.4)
Requirement already satisfied: ipaddress in /usr/lib/python2.7/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (1.0.16)
Requirement already satisfied: cffi>=1.4.1 in /usr/lib64/python2.7/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (1.6.0)
Requirement already satisfied: pycparser in /usr/lib/python2.7/site-packages (from cffi>=1.4.1->cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm==0.2.2) (2.14)
Installing collected packages: pywinrm
Successfully installed pywinrm-0.2.2
[root@localhost ~]#

これにて導入完了です。
Windowsモジュールも利用できるようになります。

オンライン環境ではコマンド一発でできますが、オフラインインストールはパッケージをバンバン入れていくため大変です…。