Hello, im using ansible-libssh (changed from paramiko) and now playbooks that worked with paramiko have diffreant behavior with ansible-libssh.
playbook:
- name: Set a hostname
become: yes
hostname:
name: test-host
use: systemd
im getting this debug:
[2024/08/07 13:36:41.471239, 2] channel_request: Channel request shell success
<10.18.16.24> EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=oztusclwkalryowlokcecuiznderdetw] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-oztusclwkalryowlokcecuiznderdetw ; /usr/bin/python3.8 /home/user/.ansible/tmp/ansible-tmp-1723027001.008096-21354-99267291740428/AnsiballZ_hostname.py'"'"' && sleep 0'
[2024/08/07 13:36:41.471604, 2] grow_window: growing window (channel 50:2) to 1280000 bytes
[2024/08/07 13:36:46.550363, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:36:51.556962, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:36:56.561486, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:37:01.566880, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:37:06.569090, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:37:11.575579, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:41:31.695995, 2] channel_rcv_request: Responding to Openssh's keepalive
[2024/08/07 13:41:36.699567, 2] channel_rcv_request: Responding to Openssh's keepalive
test-server failed: {
"changed": false,
"module_stderr": "",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": -1
}
Now if i use this command that libssh user like that:
ssh root@10.0.0.1 'sudo -H -S -p "[sudo via ansible, key=oztusclwkalryowlokcecuiznderdetw] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-oztusclwkalryowlokcecuiznderdetw ; /usr/bin/python3.8 /home/user/.ansible/tmp/ansible-tmp-1723027001.008096-21354-99267291740428/AnsiballZ_hostname.py'"'"' && sleep 0'
It will pop a request for password so im gussing it is wating for interactive pass? how do i solve this?
I will add that i tried to use become with user “user” insead of root and it worked but changing hostname is require to use root if i use a simple play
like:
shell: “ls -l”
with become: yes
it will work if i add to inventory
ansible_become_user=user
but if its user root (as it usally should be) it doesnt work
here are my conf files:
Inventory file:
[servers:vars]
ansible_ssh_private_key_file=~/.ssh/id_rsa.user
ansible_connection=ansible.netcommon.libssh
ansible_ssh_retries=3
[servers]
test-server ansible_host=10.0.0.1 ansible_become_pass=pass ansible_ssh_pass=pass
ansible.cfg:
[defaults]
transport = libssh
inventory = inventory/default.ini
host_key_checking = False
use_persistent_connections = True
ansible_python_interpreter = /usr/local/bin/python3
forks = 20
timeout = 60
stdout_callback = unixy
[libssh_connection]
remote_user = user
config_file = ~/.ssh
ssh_type = libssh
host_key_auto_add = True
use_persistent_connections = True
timeout = 60
pipelining = True
[persistent_connection]
ssh_type = libssh
command_timeout=120
connect_timeout=600
ansible==10.2.0
ansible-core==2.17.2
ansible-pylibssh==1.2.2