Closed FelipoAntonoff closed 2 years ago
Hi @FelipoAntonoff would you mind posting the inventory file here? I’m specifically interested in any env data or config that could be causing this.
The error here looks like a list is being passed as env instead of a dictionary but can’t be certain.
Hello @Fizzadar , here is the inventory used:
# https://github.com/Fizzadar/pyinfra/blob/current/examples/inventory.py https://docs.pyinfra.com/en/1.x/cli.html#inventory
local = [
# Vagrant Local ou VM
'@local'
]
dev = [
# Digital Ocean Local
('159.89.243.96',
{
'name': 'Digital Ocean Dev',
'ssh_port': '2222',
'ssh_user': 'root',
'ssh_key': '/etc/ssh_vagrant/DigitalOcean122021.key',
'ssh_key_password': '....'
}
)
]
From what I can see, it connects the machine, but when it starts running, for example, an apt or another resource, the error appears.
Locally in Vagrant I keep running some scripts and all of them getting normal if I use @local .
Not sure if this is too late, but I encountered the same problem.
Turns out that the this only happens from v1.5 onwards. For me it was because previously host.data.*
wasn't considered for global arguments (https://github.com/Fizzadar/pyinfra/releases/tag/v1.5) and we were using host.data.env
as a string instead of a dictionary. Ultimately, when you try to update
a dict with a string that's the error that comes up!
@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.
v2 & _
prefixed global arguments are now live :)
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.
@FelipoAntonoff amazing! Thank you for following up, much apprecaited :)
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:
Support information Cloud 159.89.243...
Install by pip.
Return debug:
If I also run on the test.py file:
Returns the error:
@local catches normally Already the
lsb_release = host.fact.lsb_release
gets in the Cloud tooContent File teste.py:
Run:
pyinfra /home/vagrant/pyinfra/inventory.py --limit 159.89.243.96 /home/vagrant/pyinfra/teste.py -vv --debugg
ERROR Connection OKLocal:
pyinfra /home/vagrant/pyinfra/inventory.py --limit @local /home/vagrant/pyinfra/teste.py -vv --debug
OK