question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem to run command on external host (Cloud)

See original GitHub issue

Describe the bug

Problem to run command on external host Normal runs if @local, but for the Cloud the error

To Reproduce

Example command: pyinfra /home/vagrant/pyinfra/inventory.py --limit 159.89.243.96 --debug exec -- echo "hello world"

Expected behavior

It was to return like @local: Beginning operation run… –> Starting operation: Server/Shell (echo hello world) [pyinfra.api.operations] Starting operation Server/Shell on @local [pyinfra.api.connectors.local] --> Running command on localhost: sh -c ‘echo hello world’ [@local] hello world

Meta

Support information Local run Vagrant port open:

    System: Linux
      Platform: Linux-5.10.0-9-amd64-x86_64-with-glibc2.31
      Release: 5.10.0-9-amd64
      Machine: x86_64
    pyinfra: v1.5
    Executable: /usr/local/bin/pyinfra
    Python: 3.9.2 (CPython, GCC 10.2.1 20210110)

Support information Cloud 159.89.243…

  System: Linux
      Platform: Linux-5.10.0-10-amd64-x86_64-with-glibc2.17
      Release: 5.10.0-10-amd64
      Machine: x86_64
    pyinfra: v1.5
    Executable: /usr/local/bin/pyinfra
    Python: 3.8.2 (CPython, GCC 4.9.2)

Install by pip.

Return debug:

[159.89.243...] Connected
    [pyinfra.api.state] Activating host: 159.89.243..
--> An unexpected internal exception occurred:

  File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation_kwargs.py", line 59, in generate_env
    env.update(value)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
    [pyinfra_cli.exceptions]   File "/usr/local/lib/python3.9/dist-packages/pyinfra_cli/main.py", line 236, in cli
    _main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pyinfra_cli/main.py", line 594, in _main
    add_op(
  File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation.py", line 95, in add_op
    results[host] = op_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation.py", line 183, in decorated_func
    global_kwargs, global_kwarg_keys = pop_global_op_kwargs(state, host, kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation_kwargs.py", line 171, in pop_global_op_kwargs
    value = handler(state.config, value)
  File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation_kwargs.py", line 59, in generate_env
    env.update(value)

    [pyinfra_cli.exceptions] ValueError: dictionary update sequence element #0 has length 1; 2 is required


--> The full traceback has been written to pyinfra-debug.log
--> If this is unexpected please consider submitting a bug report on GitHub, for more information run `pyinfra --support`.

If I also run on the test.py file:

apt.packages(
     name='Install Docker',
     packages=['podman'],
     present=True
)

Returns the error:

   File "/usr/local/lib/python3.9/dist-packages/pyinfra_cli/util.py", line 80, in exec_file
     exec(PYTHON_CODES[filename], date)
   File "/home/vagrant/pyinfra/teste.py", line 16, in <module>
     apt.packages(
   File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation.py", line 183, in decorated_func
     global_kwargs, global_kwarg_keys = pop_global_op_kwargs(state, host, kwargs)
   File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation_kwargs.py", line 171, in pop_global_op_kwargs
     value = handler(state.config, value)
   File "/usr/local/lib/python3.9/dist-packages/pyinfra/api/operation_kwargs.py", line 59, in generate_env
     env.update(value)
ValueError: dictionary update sequence element #0 has length 1; 2 is required

@local catches normally Already the lsb_release = host.fact.lsb_release gets in the Cloud too

Content File teste.py:

from pyinfra import config, host, logger
from pyinfra.operations import apt, server, files, pip
from pyinfra.facts.files import File
from pyinfra.facts.server import *

import json
import sys

config.SUDO = True
# If the remote system requires a password for sudo, un-comment the line below:
# USE_SUDO_PASSWORD = True

lsb_release = host.fact.lsb_release
#sys.stdout.write(lsb_release['id'])

apt.packages(
    name='Instalar Podman',
    packages=['podman'],
    present=True
)

Run: pyinfra /home/vagrant/pyinfra/inventory.py --limit 159.89.243.96 /home/vagrant/pyinfra/teste.py -vv --debugg ERROR Connection OK

Local: pyinfra /home/vagrant/pyinfra/inventory.py --limit @local /home/vagrant/pyinfra/teste.py -vv --debug OK

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Fizzadarcommented, Feb 18, 2022

@edmond-edited YES! This suddenly makes sense, a side effect I had not considered. I’ve applied a workaround in https://github.com/Fizzadar/pyinfra/commit/1c2b0edd3c8c51fafd576e91482ff204907349c1 and released that in v1.6.2. @FelipoAntonoff does this also fix your issue?

Long term the plan is now to prefix all the global arguments with _ which will prevent such issues.

1reaction
FelipoAntonoffcommented, Jul 1, 2022

Hi @Fizzadar , thank you very much.

I ran the new version and it’s getting 100% even for external host.

Solved my problem. Sorry for the delay in testing.

I ran a test with server.shell, files.get, apt.packages and others and they all started normally on the Cloud, even very quickly as if I had it in the Cloud terminal, detail I’m running Pyinfra in São Paulo/Brazil and Cloud is in the USA.

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Commands on a Remote Linux / UNIX Host
Explains how to execute or run a commands on a remote Linux or Unix host server using the ssh command and get output...
Read more >
Troubleshoot Cloud Run issues
The following error occurs when you try to deploy or try to call another Google Cloud API: The server has encountered an internal...
Read more >
How to fix 8 common remote desktop connection problems
msc command at the Windows Run prompt. Navigate through the console tree to Computer Configuration \ Windows Settings \ Security Settings \ ...
Read more >
Need remote access to Altavault using script.Unable to run ...
I am able to login to the altavault from linux machine using ssh command.But when I try to ssh to connect to altavault...
Read more >
AWS Systems Manager Run Command
Remotely manage the configuration of your EC2 instances, edge devices, and on-premises servers and VMs by using Systems Manager Run Command.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found