[WARNING]: Unhandled error in Python interpreter....

I have a task that works fine for Ansible 2.9.7, but fails when I upgrade to 2.10.3.

yaml

- name: Ping ServiceNow IP Address
shell: "ping -c 1 -w 5 {{ sn_ip_address | trim }}"

ignore_errors: true
register: ping_result_sn_ip_address_raw
when: sn_ip_address | trim | ipv4
failed_when: false
changed_when: false
delegate_to: localhost

When the task is run with Ansible 2.10.3, I receive:

[WARNING]: Unhandled error in Python interpreter discovery for host
some_snow_host: Failed to connect to the host via ssh: ssh: connect to host
localhost port 22: Cannot assign requested address
fatal: [some_snow_host]: UNREACHABLE! => {
“changed”: false,
“unreachable”: true
}

MSG:

Data could not be sent to remote host “localhost”. Make sure this host can be reached over ssh: ssh: connect to host localhost port 22: Cannot assign requested address

Note: there are other tasks in the same playbook that use “delegate_to: localhost” that work fine, although those tasks are not using the “shell” module.

Update: I found that:

  • 2.9.8, 2.9.9 also work as expected.
  • 2.9.10, 2.9.12, 2.9.15 exhibit the same error as with 2.10.3
    Basically, I built my docker images with different Ansible versions until I found the “breaking point” between 2.9.9 and 2.9.10 :slight_smile:

I guess I’ll open an issue on the project, but if anybody has any input please feel free to respond.

I have a task that works fine for Ansible 2.9.7, but fails when I upgrade
to 2.10.3.
...
Data could not be sent to remote host "localhost". Make sure this host can
be reached over ssh: ssh: connect to host localhost port 22: Cannot assign
requested address

FWIW, I'm still on 2.9.6.

As a hint, try to find out why *ssh* connection plugin is used to
connect localhost. IMHO, the default is *local*. For example, testing
with no configuration of the connection ("cat hosts | grep
connection" shows nothing)

  > cat pb.yml
  - hosts: test_01
    tasks:
      - debug:
          var: ansible_connection
      - debug:
          var: ansible_connection
        delegate_to: localhost

gives

  TASK [debug] ****
  ok: [test_01] =>
    ansible_connection: ssh

  TASK [debug]****
  ok: [test_01 -> localhost] =>
    ansible_connection: local

See DEFAULT_TRANSPORT
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-transport

"man ansible" says

      -v, --verbose
          verbose mode (-vvv for more, -vvvv to enable connection
          debugging)

For example

  > ansible-playbook pb.yml -vvvv | grep connection
  connection: smart
    ansible_connection: ssh
    ansible_connection: local

Thank you. I did open an ansible github issue and subsequently closed it based on respondents there. Your comments above definitely helped. Seems 2.9.10 fixed “buggy behavior” that I was relying on by not explicitly using “connection: local”.