ansible-collections / ansible.netcommon

Ansible Network Collection for Common Code
GNU General Public License v3.0
143 stars 104 forks source link

Ansible-libssh unable to use “become” #662

Closed batchenr closed 2 months ago

batchenr commented 3 months ago

Hello, im using ansible-libssh (changed from paramiko) and now playbooks that worked with paramiko have different behavior with ansible-libssh.

using:

ansible==10.2.0
ansible-core==2.17.2
ansible-pylibssh==1.2.2
ansible.netcommon      6.1.3

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 guessing it is waiting for interactive pass? Also, I tried to use become with user “user” instead of root and it worked but changing hostname is require to use root. If i use a simple play like this:

- name: "test play"
  become: yes
  shell: “ls -l”

It will work with inventory entry: ansible_become_user=user but if its user root (as it usually should be) it doesn't work.

configuration 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
NilashishC commented 2 months ago

@batchenr Looking at the description of this issue, it should be opened in ansible/pylibssh and not this one.

Closing this ticket as per above. Thanks!