Win10でネイティブにAnsibleを実行したかった件
結論
Windows Frequently Asked Questions · ansible/ansible にある通り、現状、Windowsから直接Ansibleは実行出来ない(但し、WSL経由ならいける)。
Can Ansible run on Windows? No, Ansible can only manage Windows hosts. Ansible cannot run on a Windows host natively, though it can run under the Windows Subsystem for Linux (WSL).
環境
-- | -- |
---|---|
エディション | Windows 10 Pro |
バージョン | 21H1 |
インストール日 | 2020/08/23 |
OS ビルド | 19043.964 |
エクスペリエンス | Windows Feature Experience Pack 120.2212.3740.0 |
モチベ
Win10 Homeで、VagrantでHyper-V使ってVM起動する際に、 初回の作業(特定のユーザ作ってSSH鍵追加したり、dnf updateとか)がダルいので自動化したい、、、
んで、Provisionerにちょうどよいのないかなぁとドキュメント読んでたら、 VagrantのProvisionerにAnsibleが使えるって事で試そうとした。
やった事
pythonのインストール
以下にある通り、パッケージをDLってインストール。 www.python.jp
仮想環境の作成&ansibleのインストール
ansibleがwinネイティブに使えるなら他にも使いたいので、venvを使って環境を分ける。
❯ py -m venv --without-pip .venv ❯ .venv\Scripts\activate.ps1 ❯ curl https://bootstrap.pypa.io/get-pip.py ❯ py get-pip.py ❯ py -m pip install -r requirements.txt
requirements.txt
flake8 pytest cryptography jmespath == 0.9.5 PyYAML >= 5.4.1 ansible-base <2.11,>=2.10.7 yamllint >=1.25.0 ansible-lint >=5.0.0 python-vagrant >= 0.5.15
上手くいくかと思ったけど、以下のエラー
❯ py -m pip install ansible-base==2.10.9 Collecting ansible-base==2.10.9 Using cached ansible-base-2.10.9.tar.gz (6.0 MB) Requirement already satisfied: jinja2 in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from ansible-base==2.10.9) (2.11.3) Requirement already satisfied: PyYAML in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from ansible-base==2.10.9) (5.4.1) Requirement already satisfied: cryptography in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from ansible-base==2.10.9) (3.4.7) Requirement already satisfied: packaging in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from ansible-base==2.10.9) (20.9) Requirement already satisfied: cffi>=1.12 in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from cryptography->ansible-base==2.10.9) (1.14.5) Requirement already satisfied: pycparser in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from cffi>=1.12->cryptography->ansible-base==2.10.9) (2.20) Requirement already satisfied: MarkupSafe>=0.23 in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from jinja2->ansible-base==2.10.9) (1.1.1) Requirement already satisfied: pyparsing>=2.0.2 in c:\users\yassan\vargant\hoge\.venv\lib\site-packages (from packaging->ansible-base==2.10.9) (2.4.7) Building wheels for collected packages: ansible-base Building wheel for ansible-base (setup.py) ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\yassan\vargant\hoge\.venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\yassan\\AppData\\Local\\Temp\\pip-install-4p46nnmv\\ansible-base_68e8945aa34749959f5671f4bb8c4177\\setup.py'"'"'; __file__='"'"'C:\\Users\\yassan\\AppData\\Local\\Temp\\pip-install-4p46nnmv\\ansible-base_68e8945aa34749959f5671f4bb8c4177\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\yassan\AppData\Local\Temp\pip-wheel-tymwpqt_' cwd: C:\Users\yassan\AppData\Local\Temp\pip-install-4p46nnmv\ansible-base_68e8945aa34749959f5671f4bb8c4177\ Complete output (951 lines): running bdist_wheel : creating build\lib\ansible_test\_data\sanity\yamllint copying test\lib\ansible_test\_data\sanity\yamllint\yamllinter.py -> build\lib\ansible_test\_data\sanity\yamllint creating build\lib\ansible_test\_data\sanity\yamllint\config copying test\lib\ansible_test\_data\sanity\yamllint\config\default.yml -> build\lib\ansible_test\_data\sanity\yamllint\config copying test\lib\ansible_test\_data\sanity\yamllint\config\modules.yml -> build\lib\ansible_test\_data\sanity\yamllint\config copying test\lib\ansible_test\_data\sanity\yamllint\config\plugins.yml -> build\lib\ansible_test\_data\sanity\yamllint\config creating build\lib\ansible_test\_data\setup copying test\lib\ansible_test\_data\setup\ConfigureRemotingForAnsible.ps1 -> build\lib\ansible_test\_data\setup copying test\lib\ansible_test\_data\setup\docker.sh -> build\lib\ansible_test\_data\setup copying test\lib\ansible_test\_data\setup\remote.sh -> build\lib\ansible_test\_data\setup copying test\lib\ansible_test\_data\setup\windows-httptester.ps1 -> build\lib\ansible_test\_data\setup creating build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-aws.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-azure.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-cloudscale.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-cs.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-gcp.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-hcloud.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-opennebula.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-openshift.kubeconfig.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-scaleway.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-tower.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-vcenter.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\cloud-config-vultr.ini.template -> build\lib\ansible_test\config copying test\lib\ansible_test\config\inventory.networking.template -> build\lib\ansible_test\config : copying test\lib\ansible_test\config\inventory.winrm.template -> build\lib\ansible_test\config error: symbolic link privilege not held ---------------------------------------- ERROR: Failed building wheel for ansible-base Running setup.py clean for ansible-base Failed to build ansible-base Installing collected packages: ansible-base Running setup.py install for ansible-base ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\yassan\vargant\hoge\.venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\yassan\\AppData\\Local\\Temp\\pip-install-4p46nnmv\\ansible-base_68e8945aa34749959f5671f4bb8c4177\\setup.py'"'"'; __file__='"'"'C:\\Users\\yassan\\AppData\\Local\\Temp\\pip-install-4p46nnmv\\ansible-base_68e8945aa34749959f5671f4bb8c4177\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\yassan\AppData\Local\Temp\pip-record-9tp3_0q8\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\yassan\vargant\hoge\.venv\include\site\python3.6\ansible-base' cwd: C:\Users\yassan\AppData\Local\Temp\pip-install-4p46nnmv\ansible-base_68e8945aa34749959f5671f4bb8c4177\ Complete output (949 lines): running install running build running build_py creating build creating build\lib : copying test\lib\ansible_test\config\inventory.winrm.template -> build\lib\ansible_test\config error: symbolic link privilege not held ---------------------------------------- ERROR: Command errored out with exit status 1: 'C:\Users\yassan\vargant\hoge\.venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\yassan\\AppData\\Local\\Temp\\pip-install-4p46nnmv\\ansible-base_68e8945aa34749959f5671f4bb8c4177\\setup.py'"'"'; __file__='"'"'C:\\Users\\yassan\\AppData\\Local\\Temp\\pip-install-4p46nnmv\\ansible-base_68e8945aa34749959f5671f4bb8c4177\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\yassan\AppData\Local\Temp\pip-record-9tp3_0q8\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\yassan\vargant\hoge\.venv\include\site\python3.6\ansible-base' Check the logs for full command output.
結論にある通り、FAQ見たら動かないとの事。。残念。
Can Ansible run on Windows? No, Ansible can only manage Windows hosts. Ansible cannot run on a Windows host natively, though it can run under the Windows Subsystem for Linux (WSL).