I use fabric 2.6.0, paramiko 2.9.2 and invoke 1.4.0
Is this bug or something incompatible I got an error like this.
File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py", line 274, in add_string self.add_int(len(s)) TypeError: object of type 'bool' has no len()
when I set dry=True
I got like this.
>>> conn.run('touch hello.txt', dry=True)
touch hello.txt
<Result cmd='touch hello.txt' exited=0>
Here's the complete Error that I got.
Python 3.7.5 (default, Dec 9 2021, 17:04:37)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fabric import Connection
>>> conn = Connection('192.168.1.16')
>>> conn.open()
>>> conn.is_connected
True
>>> conn.run('touch hello.txt')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<decorator-gen-3>", line 2, in run
File "/usr/local/lib/python3.7/dist-packages/fabric/connection.py", line 30, in opens
return method(self, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/fabric/connection.py", line 723, in run
return self._run(self._remote_runner(), command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/context.py", line 102, in _run
return runner.run(command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/runners.py", line 380, in run
return self._run_body(command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/runners.py", line 431, in _run_body
self.start(command, self.opts["shell"], self.env)
File "/usr/local/lib/python3.7/dist-packages/fabric/runners.py", line 57, in start
self.channel.update_environment(env)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 332, in update_environment
self.set_environment_variable(name, value)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 361, in set_environment_variable
m.add_string(value)
File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py", line 274, in add_string
self.add_int(len(s))
TypeError: object of type 'bool' has no len()
and here my ssh config
Host *
Port 22
User ubuntu
IdentityFile /home/ubuntu/.ssh/id_rsa
when I run ssh 192.168.1.16
from shell can successfully connect with remote machine.
After debugging for a while, I realize that this error happen because of miss configuration.
The thing that actually happen is that I put some environment variable on fabric.yaml
so that will loaded automatically when fabric run and the problem happen when I want to open connection to the remote server.
What happen in the back when I run command with fabric is, fabric will open ssh connection using paramiko and then try to send the local environment variable that I set in fabric.yaml to the remote machine (this thing that cause the error)
You can't send environment variable form local machine to remote using ssh without put the setting into your sshd_config for the SendEnv
and AcceptEnv
for your local and remote machine or the alternatives is enable PermitUserEnvironment yes
this only for remote machine and don't forget to create environment
file in your remote home directory (home when you do ssh).
Hope my mistake can help another who also has similiar problem.