我正在尝试从sh
导入anisble playbook模块>>>> from sh import ansible-playbook
File "<stdin>", line 1
from sh import ansible-playbook
^
SyntaxError: invalid syntax
我还试图安装libs“ansible”和“ansible-playbook”
pip install ansible
/home/mfusion/pypy/bin/pypy: /lib64/libssl.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
/home/mfusion/pypy/bin/pypy: /lib64/libssl.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
/home/mfusion/pypy/bin/pypy: /lib64/libcrypto.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
Collecting ansible
Downloading ansible-2.3.2.0.tar.gz (4.3MB)
100% |################################| 4.3MB 292kB/s
Collecting jinja2 (from ansible)
Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB)
100% |################################| 348kB 5.3MB/s
Requirement already satisfied (use --upgrade to upgrade): PyYAML in ./pypy/site-packages (from ansible)
Collecting paramiko (from ansible)
Downloading paramiko-2.2.1-py2.py3-none-any.whl (176kB)
100% |################################| 184kB 6.5MB/s
Collecting pycrypto>=2.6 (from ansible)
Downloading pycrypto-2.6.1.tar.gz (446kB)
100% |################################| 450kB 2.8MB/s
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./pypy/site-packages (from ansible)
Collecting MarkupSafe>=0.23 (from jinja2->ansible)
Downloading MarkupSafe-1.0.tar.gz
Collecting bcrypt>=3.1.3 (from paramiko->ansible)
Downloading bcrypt-3.1.3.tar.gz (40kB)
100% |################################| 40kB 7.6MB/s
Collecting cryptography>=1.1 (from paramiko->ansible)
Downloading cryptography-2.0.3.tar.gz (427kB)
100% |################################| 430kB 2.6MB/s
Complete output from command python setup.py egg_info:
/home/mfusion/pypy/bin/pypy: /lib64/libssl.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
/home/mfusion/pypy/bin/pypy: /lib64/libssl.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
/home/mfusion/pypy/bin/pypy: /lib64/libcrypto.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-IsodPx/cryptography/setup.py", line 52, in <module>
"cryptography 1.9 is not compatible with PyPy < 5.3. Please "
RuntimeError: cryptography 1.9 is not compatible with PyPy < 5.3. Please upgrade PyPy to use this library.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-IsodPx/cryptography/
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
pip install ansible-playbook
/home/mfusion/pypy/bin/pypy: /lib64/libssl.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
/home/mfusion/pypy/bin/pypy: /lib64/libssl.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
/home/mfusion/pypy/bin/pypy: /lib64/libcrypto.so.1.0.0: no version information available (required by /home/mfusion/pypy/bin/libpypy-c.so)
Collecting ansible-playbook
Could not find a version that satisfies the requirement ansible-playbook (from versions: )
No matching distribution found for ansible-playbook
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
CoreOS是平台,我使用python作为二进制文件。我有 在这里查看了一些在线建议Python Module with a dash, or hyphen (-) in its name并尝试了这个
>>>> __import__("ansible-playbook")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ansible-playbook
exec("ansible-playbook")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: global name 'ansible' is not defined
请帮忙...... 最好,我想从sh
导入ansible-playbook就我而言,我借助bash命令别名来解决这个问题
答案 0 :(得分:0)
ansible-playbook 是命令行剧本执行者,您无法将其导入您的代码。
相反,你可以导入像,
来自ansible.executor.playbook_executor的导入PlaybookExecutor
PlaybookExecutor通过传递args来执行ansible playbook,
PlaybookExecutor(playbooks,inventory,variable_manager,loader,options,passwords)