-2

I am trying to import anisble playbook module from sh

>>>> from sh import ansible-playbook
  File "<stdin>", line 1
    from sh import ansible-playbook
                         ^
SyntaxError: invalid syntax

I have also tried to install libs "ansible" and "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 is the platform and I am using python as a binary. I have looked at some online suggestions here Python Module with a dash, or hyphen (-) in its name and tried this

>>>> __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

Please help... Preferably, I want import ansible-playbook from sh

In my case, I took the help of bash command alias to solve this problem

CuriousTechie
  • 413
  • 2
  • 8
  • 21

1 Answers1

0

ansible-playbook is command line playbook executor, you can't import it into your code.

Instead you can import like,

from ansible.executor.playbook_executor import PlaybookExecutor

PlaybookExecutor execute the ansible playbook by passing args like,

PlaybookExecutor(playbooks, inventory, variable_manager, loader, options, passwords)