From discord:
Hello, I'm a new user of pyinfra, and I have an issue with the sudo mechanism, but most probably there is a problem with my config.
In the inventory.py I have a home group, and running only one operation:
files.directory(
name="Ensure /etc/nebula exists",
path="/etc/nebula",
present=True,
sudo=True,
use_sudo_password=host.data.sudo_password,
)
sudo_password is part of the inventory config. It's working fine, if I have only one machine in inventory which needs sudo.
When I'm adding a second one, there is an error with the sudo command:
[machine.local] >>> env SUDO_ASKPASS=pyinfra-sudo-askpass *** sudo -H -A -k sh -c '! test -e /etc/nebula || (stat -c '"'"'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N'"'"' /etc/nebula 2> /dev/null || stat -f '"'"'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY'"'"' /etc/nebula)'
[machine.local] sudo: unable to run pyinfra-sudo-askpass: Exec format error
[machine.local] sudo: no password was provided
[machine.local] sudo: a password is required
It doesn't matter if theay are in the same group or not. One additional info: They are using the same user, same password, one machine is using a key, the other one is using password for the ssh connection. It's working with both of them separately, but not together...
With PARALLEL = 1 config it works like a charm, but I'm not sure why.
Can confirm in 1.4.3, I am experiencing this issue.
First server works fine, the rest will fail.
Short term solutions that have worked for me:
PARALLEL=1 in config.py.--limit= when running pyinfraError:
[machine_ip_c] sudo: unable to run pyinfra-sudo-askpass: Exec format error
[machine_ip_c] sudo: no password was provided
[machine_ip_c] Error
[machine_ip_b] sudo: unable to run pyinfra-sudo-askpass: Exec format error
[machine_ip_b] sudo: no password was provided
[machine_ip_b] Error
[machine_ip_a] Success
Also thanks @Fizzadar for pro-actively tracking this issue, I appreciate that.
Confirmed in v1.4.4 when I ran a deploy against real machines rather than the usual cohort of lxd instances I typically test with that don't require a password for SUDO. Adding "use_sudo_password=True" to operations triggered the issue as soon as I ran the deploy against more than one machine. The issue was observed during dry run as well as the actual deploy.
PARALLEL=1 in config.py was a viable workaround.
Finally got to the bottom of this - reuse of the same StringIO object; fixed in https://github.com/Fizzadar/pyinfra/commit/07f9d6c80612f12e0faf394d54c9cb1929c42577 & released just now in v1.4.5!
Fix confirmed. Deploys no longer need PARALLEL=1 to work properly.