pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
--> Connecting to hosts...
[@vagrant/mailvm-dev] Connected
--> Preparing operations...
Loading: bugvm.py
Traceback (most recent call last):
File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 68, in exec_file
exec(PYTHON_CODES[filename], data)
File "bugvm.py", line 2, in
from pyinfra.operations import dnf, server, init, files, postgresql
ImportError: cannot import name 'init' from 'pyinfra.operations' (/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra/operations/init.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 232, in load_file
exec_file(filename)
File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 72, in exec_file
raise UnexpectedExternalError(e, filename)
pyinfra_cli.exceptions.UnexpectedExternalError:
2022-06-24T21:14:06Z <Greenlet at 0x7fb472a44940: load_file(Host(@vagrant/mailvm-dev))> failed with UnexpectedExternalError
--> An unexpected exception occurred in: bugvm.py:
File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 68, in exec_file
exec(PYTHON_CODES[filename], data)
File "bugvm.py", line 2, in
from pyinfra.operations import dnf, server, init, files, postgresql
ImportError: cannot import name 'init' from 'pyinfra.operations' (/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra/operations/init.py)
bugvm.py
import sys
from pyinfra.operations import dnf, server, init, files, postgresql
from pyinfra import host
Expected behavior
to be able to run code like
init.systemd(
name='Restart and enable the {} service'.format(service),
service='{}.service'.format(service),
running=True,
restarted=True,
enabled=True,
)
Meta
Include output of pyinfra --support.
23:11:39-joakim@tanaka:~/infra/vagrant_mail_vm$ pyinfra --support
--> Support information:
If you are having issues with pyinfra or wish to make feature requests, please
check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
When adding an issue, be sure to include the following:
Describe the bug
While trying to run an old pyinfra script, I get ImportError: cannot import name 'init' from 'pyinfra.operations'
23:12:56-joakim@tanaka:~/infra/vagrant_mail_vm$ pyinfra inventory-dev.py bugvm.py --> Loading config... --> Loading inventory... Getting Vagrant config...
--> Connecting to hosts... [@vagrant/mailvm-dev] Connected
--> Preparing operations... Loading: bugvm.py Traceback (most recent call last): File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 68, in exec_file exec(PYTHON_CODES[filename], data) File "bugvm.py", line 2, in
from pyinfra.operations import dnf, server, init, files, postgresql
ImportError: cannot import name 'init' from 'pyinfra.operations' (/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra/operations/init.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 232, in load_file exec_file(filename) File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 72, in exec_file raise UnexpectedExternalError(e, filename) pyinfra_cli.exceptions.UnexpectedExternalError:
2022-06-24T21:14:06Z <Greenlet at 0x7fb472a44940: load_file(Host(@vagrant/mailvm-dev))> failed with UnexpectedExternalError
--> An unexpected exception occurred in: bugvm.py:
File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 68, in exec_file exec(PYTHON_CODES[filename], data) File "bugvm.py", line 2, in
from pyinfra.operations import dnf, server, init, files, postgresql
ImportError: cannot import name 'init' from 'pyinfra.operations' (/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra/operations/init.py)
To Reproduce
inventory-dev.py
mail_dev = [ ('@vagrant/mailvm-dev', {'production':False, 'fqdn':'mboxdev.verona.se'}) ]
bugvm.py import sys from pyinfra.operations import dnf, server, init, files, postgresql from pyinfra import host
Expected behavior
to be able to run code like
Meta
Include output of
pyinfra --support
. 23:11:39-joakim@tanaka:~/infra/vagrant_mail_vm$ pyinfra --support --> Support information:If you are having issues with pyinfra or wish to make feature requests, please check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues . When adding an issue, be sure to include the following:
System: Linux Platform: Linux-5.18.5-200.fc36.x86_64-x86_64-with-glibc2.35 Release: 5.18.5-200.fc36.x86_64 Machine: x86_64 pyinfra: v2.2 Executable: /home/joakim/.local/bin/pyinfra Python: 3.10.4 (CPython, GCC 12.0.1 20220308 (Red Hat 12.0.1-0))
-vv
and--debug
.