Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables inventory_hostname, remote_user don't contain the correct value #641

Open
urohit011 opened this issue May 29, 2024 · 6 comments
Open
Assignees
Labels
needs_info This issue requires further information. Please answer any outstanding questions.

Comments

@urohit011
Copy link

SUMMARY

When using the netcommon collection for connection purpose, sometimes values of variables such as, inventory_hostname, remote_user and password are somehow not being used correctly which results in the error:

[Errno -3] Temporary failure in name resolution

And I found the following entry in the ansible.log file

<inventory_hostname> ESTABLISH PARAMIKO SSH CONNECTION FOR USER: None on PORT 22 TO inventory_hostname

I think this could be happening after this PR ansible/ansible#79704, was merged in ansible fix a very similar issue. In short the PR has changes in paramiko_ssh.py where references like connection._play_context("remote_addr") were changed to connection.get_option("remote_addr"), which is not retrieving the correct value. I think that is happening because in this following snippet, the variables variable on on line 75, only contains ansible_command_timeout:

def run(self):
"""Returns the path of the persistent connection socket.
Attempts to ensure (within playcontext.timeout seconds) that the
socket path exists. If the path exists (or the timeout has expired),
returns the socket path.
"""
display.vvvv(
"starting connection from persistent connection plugin",
host=self._play_context.remote_addr,
)
variables = {"ansible_command_timeout": self.get_option("persistent_command_timeout")}
socket_path = start_connection(self._play_context, variables, self._task_uuid)
display.vvvv(
"local domain socket path is %s" % socket_path,
host=self._play_context.remote_addr,
)
setattr(self, "_socket_path", socket_path)
return socket_path

When the I changed variables to the following, I didn't get the error and it worked fine for me.

variables = {
            "ansible_command_timeout": self.get_option(
                "persistent_command_timeout"
            ),
            "remote_addr": self.get_option("remote_addr"),
            "remote_user": self.get_option("remote_user"),
            "password": self.get_option("password"),
            "port": self.get_option("port"),
            "private_key_file": self.get_option("private_key_file")
        }
ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.netcommon

ANSIBLE VERSION
ansible [core 2.15.12] and later
COLLECTION VERSION
ansible.netcommon   v5.1.1
CONFIGURATION

OS / ENVIRONMENT

ubuntu

STEPS TO REPRODUCE

Run the below playbook with ansible version 2.15.12 or later, you do not need a bigip box, you can provide a random IP, username and password

---
- name: Test
  hosts: bigip
  gather_facts: true
  connection: local

  vars:
    provider:
     server: "1.2.3.4"
     user: user
     password: pass
     validate_certs: no
     transport: cli
     server_port: 22
     no_f5_teem: yes

  tasks:
    - name: test
      bigip_command:
        commands:
          - show sys version
        provider: "{{ provider }}"

You'll get the error, [Errno -3] Temporary failure in name resolution
and the below entry in ansible.log file
<inventory_hostname> ESTABLISH PARAMIKO SSH CONNECTION FOR USER: None on PORT 22 TO inventory_hostname

EXPECTED RESULTS

It should not fail with the error, [Errno -3] Temporary failure in name resolution

ACTUAL RESULTS

It's failing with the error

The full traceback is:
Traceback (most recent call last):
  File "/home/ubuntu/ansible_cfgs/py310/lib/python3.10/site-packages/ansible/executor/task_executor.py", line 165, in run
    res = self._execute()
  File "/home/ubuntu/ansible_cfgs/py310/lib/python3.10/site-packages/ansible/executor/task_executor.py", line 656, in _execute
    result = self._handler.run(task_vars=vars_copy)
  File "/home/ubuntu/f5-ansible/ansible_collections/f5networks/f5_modules/plugins/action/bigip.py", line 96, in run
    out = conn.get_prompt()
  File "/home/ubuntu/ansible_cfgs/py310/lib/python3.10/site-packages/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
ansible.module_utils.connection.ConnectionError: [Errno -3] Temporary failure in name resolution
fatal: [1.2.3.4]: FAILED! => 
  msg: 'Unexpected failure during module execution: [Errno -3] Temporary failure in name resolution'
  stdout: ''
@rohitthakur2590
Copy link
Contributor

rohitthakur2590 commented Jun 25, 2024

@urohit011 I have set/provide these variables for the connection in the action plugin itself. For instance, refer to this example: F5Networks/f5-ansible#2413
These are the changes on netcommon side https://github.com/ansible-collections/ansible.netcommon/pull/653/files

I tested setting remote_address, and it resolved correctly on my end. Could you please confirm if this solution works for you as well?

@rohitthakur2590 rohitthakur2590 added the needs_info This issue requires further information. Please answer any outstanding questions. label Jun 25, 2024
@urohit011
Copy link
Author

Hi @rohitthakur2590, I'll check and confirm once #653 is merged. Thanks

@rohitthakur2590
Copy link
Contributor

@urohit011 Thanks, meanwhile could you please give detailed debug logs as well? also could you please tell us the specific versions of Netcommon and ansible core for which it was working fine before?

@rohitthakur2590
Copy link
Contributor

@urohit011
I believe the better and correct approach would be implementing the changes in PR #2413. Could you please verify if this works for you? As a result, no modifications are needed in the netcommon collection, so I am closing PR #653.

@urohit011
Copy link
Author

Hi @rohitthakur2590, apologies for late reply, changes in PR #2413 do not help unless the changes made in PR #653 re merged I had checked it when I had opened this issue.

@urohit011
Copy link
Author

Here's tha ansible logs

2024-07-30 16:00:30,799 p=36606 u=user n=ansible | ansible-playbook [core 2.17.2]
  config file = /Users/user/dev/ansible_cfgs/V1/ansible.cfg
  configured module search path = ['/Users/user/dev/f5-ansible/ansible_collections/f5networks/f5_modules/plugins/modules']
  ansible python module location = /Users/user/dev/py310/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/user/dev/f5-ansible
  executable location = /Users/user/dev/py310/bin/ansible-playbook
  python version = 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/Users/user/dev/py310/bin/python)
  jinja version = 3.1.3
  libyaml = True
2024-07-30 16:00:30,799 p=36606 u=user n=ansible | Using /Users/user/dev/ansible_cfgs/V1/ansible.cfg as config file
2024-07-30 16:00:30,800 p=36606 u=user n=ansible | setting up inventory plugins
2024-07-30 16:00:30,943 p=36606 u=user n=ansible | Loading collection ansible.builtin from 
2024-07-30 16:00:30,952 p=36606 u=user n=ansible | Parsed /Users/user/dev/ansible_cfgs/hosts inventory source with ini plugin
2024-07-30 16:00:31,074 p=36606 u=user n=ansible | Loading collection community.general from /Users/user/dev/py310/lib/python3.10/site-packages/ansible_collections/community/general
2024-07-30 16:00:31,078 p=36606 u=user n=ansible | Loading callback plugin community.general.yaml of type stdout, v2.0 from /Users/user/dev/py310/lib/python3.10/site-packages/ansible_collections/community/general/plugins/callback/yaml.py
2024-07-30 16:00:31,095 p=36606 u=user n=ansible | Skipping callback 'default', as we already have a stdout callback.
2024-07-30 16:00:31,095 p=36606 u=user n=ansible | Skipping callback 'minimal', as we already have a stdout callback.
2024-07-30 16:00:31,095 p=36606 u=user n=ansible | Skipping callback 'oneline', as we already have a stdout callback.
2024-07-30 16:00:31,095 p=36606 u=user n=ansible | PLAYBOOK: bigip_cmd.yaml *********************************************************************************************************************************************************
2024-07-30 16:00:31,095 p=36606 u=user n=ansible | 1 plays in bigip_cmd.yaml
2024-07-30 16:00:31,096 p=36606 u=user n=ansible | PLAY [Test] **********************************************************************************************************************************************************************
2024-07-30 16:00:31,111 p=36606 u=user n=ansible | TASK [test] **********************************************************************************************************************************************************************
2024-07-30 16:00:31,131 p=36606 u=user n=ansible | redirecting (type: action) ansible.builtin.bigip to f5networks.f5_modules.bigip
2024-07-30 16:00:31,133 p=36606 u=user n=ansible | Loading collection f5networks.f5_modules from /Users/user/dev/f5-ansible/ansible_collections/f5networks/f5_modules
2024-07-30 16:00:31,134 p=36606 u=user n=ansible | <XX.XX.XX.XX> Using network group action bigip for bigip_command
2024-07-30 16:00:31,134 p=36606 u=user n=ansible | redirecting (type: action) ansible.builtin.bigip to f5networks.f5_modules.bigip
2024-07-30 16:00:31,137 p=36606 u=user n=ansible | Loading collection ansible.netcommon from /Users/user/dev/f5-ansible/ansible_collections/ansible/netcommon
2024-07-30 16:00:31,159 p=36606 u=user n=ansible | <XX.XX.XX.XX> connection transport is cli
2024-07-30 16:00:31,159 p=36606 u=user n=ansible | <XX.XX.XX.XX> using connection plugin network_cli
2024-07-30 16:00:31,160 p=36606 u=user n=ansible | redirecting (type: connection) ansible.builtin.persistent to ansible.netcommon.persistent
2024-07-30 16:00:31,163 p=36606 u=user n=ansible | <XX.XX.XX.XX> starting connection from persistent connection plugin
2024-07-30 16:00:31,163 p=36606 u=user n=ansible | Found ansible-connection at path /Users/user/dev/py310/bin/ansible-connection
2024-07-30 16:00:31,606 p=36611 u=user n=ansible | Loading collection ansible.builtin from 
2024-07-30 16:00:31,694 p=36614 u=user n=ansible | redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
2024-07-30 16:00:31,697 p=36614 u=user n=ansible | Loading collection ansible.netcommon from /Users/user/dev/f5-ansible/ansible_collections/ansible/netcommon
2024-07-30 16:00:31,711 p=36614 u=user n=ansible | Loading collection ansible.utils from /Users/user/dev/py310/lib/python3.10/site-packages/ansible_collections/ansible/utils
2024-07-30 16:00:31,728 p=36614 u=user n=ansible | redirecting (type: terminal) ansible.builtin.bigip to f5networks.f5_modules.bigip
2024-07-30 16:00:31,729 p=36614 u=user n=ansible | Loading collection f5networks.f5_modules from /Users/user/dev/f5-ansible/ansible_collections/f5networks/f5_modules
2024-07-30 16:00:32,416 p=36606 u=user n=ansible | <XX.XX.XX.XX> local domain socket does not exist, starting it
2024-07-30 16:00:32,417 p=36606 u=user n=ansible | <XX.XX.XX.XX> control socket path is /Users/user/.ansible/pc/9d01ffc9c1
2024-07-30 16:00:32,417 p=36606 u=user n=ansible | <XX.XX.XX.XX> Loading collection ansible.builtin from 
2024-07-30 16:00:32,417 p=36606 u=user n=ansible | <XX.XX.XX.XX> redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> Loading collection ansible.netcommon from /Users/user/dev/f5-ansible/ansible_collections/ansible/netcommon
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> Loading collection ansible.utils from /Users/user/dev/py310/lib/python3.10/site-packages/ansible_collections/ansible/utils
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> redirecting (type: terminal) ansible.builtin.bigip to f5networks.f5_modules.bigip
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> Loading collection f5networks.f5_modules from /Users/user/dev/f5-ansible/ansible_collections/f5networks/f5_modules
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> local domain socket listeners started successfully
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> unable to load cliconf for network_os bigip. Falling back to default
2024-07-30 16:00:32,418 p=36606 u=user n=ansible | <XX.XX.XX.XX> loaded cliconf plugin ansible_collections.ansible.netcommon.plugins.cliconf.default from path /Users/user/dev/f5-ansible/ansible_collections/ansible/netcommon/plugins/cliconf/default.py for network_os bigip
2024-07-30 16:00:32,419 p=36606 u=user n=ansible | network_os is set to bigip
2024-07-30 16:00:32,419 p=36606 u=user n=ansible | <XX.XX.XX.XX> ssh type is set to paramiko
2024-07-30 16:00:32,419 p=36606 u=user n=ansible | <XX.XX.XX.XX> Loading collection ansible.builtin from 

2024-07-30 16:00:32,419 p=36606 u=user n=ansible | <XX.XX.XX.XX> local domain socket path is /Users/user/.ansible/pc/9d01ffc9c1
2024-07-30 16:00:32,419 p=36606 u=user n=ansible | <XX.XX.XX.XX> socket_path: /Users/user/.ansible/pc/9d01ffc9c1
2024-07-30 16:00:32,419 p=36614 u=user n=ansible | <inventory_hostname> ESTABLISH PARAMIKO SSH CONNECTION FOR USER: None on PORT 22 TO inventory_hostname
2024-07-30 16:00:32,432 p=36614 u=user n=ansible | Traceback (most recent call last):
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 511, in _connect_uncached
    ssh.connect(
  File "/Users/user/dev/py310/lib/python3.10/site-packages/paramiko/client.py", line 377, in connect
    to_try = list(self._families_and_addresses(hostname, port))
  File "/Users/user/dev/py310/lib/python3.10/site-packages/paramiko/client.py", line 202, in _families_and_addresses
    addrinfos = socket.getaddrinfo(
  File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/utils/jsonrpc.py", line 45, in handle_request
    result = rpc_method(*args, **kwargs)
  File "/Users/user/dev/f5-ansible/ansible_collections/ansible/netcommon/plugins/connection/network_cli.py", line 343, in wrapped
    self._connect()
  File "/Users/user/dev/f5-ansible/ansible_collections/ansible/netcommon/plugins/connection/network_cli.py", line 625, in _connect
    ssh = self.ssh_type_conn._connect()
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 392, in _connect
    self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 537, in _connect_uncached
    raise AnsibleConnectionFailure(msg)
ansible.errors.AnsibleConnectionFailure: [Errno 8] nodename nor servname provided, or not known

2024-07-30 16:00:32,443 p=36606 u=user n=ansible | The full traceback is:
Traceback (most recent call last):
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/executor/task_executor.py", line 164, in run
    res = self._execute()
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/executor/task_executor.py", line 636, in _execute
    result = self._handler.run(task_vars=vars_copy)
  File "/Users/user/dev/f5-ansible/ansible_collections/f5networks/f5_modules/plugins/action/bigip.py", line 90, in run
    out = conn.get_prompt()
  File "/Users/user/dev/py310/lib/python3.10/site-packages/ansible/module_utils/connection.py", line 199, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
ansible.module_utils.connection.ConnectionError: [Errno 8] nodename nor servname provided, or not known

2024-07-30 16:00:32,443 p=36606 u=user n=ansible | fatal: [XX.XX.XX.XX]: FAILED! => 
  msg: 'Unexpected failure during module execution: [Errno 8] nodename nor servname provided, or not known'
  stdout: ''
2024-07-30 16:00:32,444 p=36606 u=user n=ansible | PLAY RECAP ***********************************************************************************************************************************************************************
2024-07-30 16:00:32,444 p=36606 u=user n=ansible | XX.XX.XX.XX             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
2024-07-30 16:00:45,646 p=36541 u=user n=ansible | persistent connection idle timeout triggered, timeout value is 30 secs.
See the timeout setting options in the Network Debug and Troubleshooting Guide.
2024-07-30 16:00:45,752 p=36541 u=user n=ansible | shutdown complete
2024-07-30 16:01:02,434 p=36614 u=user n=ansible | persistent connection idle timeout triggered, timeout value is 30 secs.
See the timeout setting options in the Network Debug and Troubleshooting Guide.
2024-07-30 16:01:02,538 p=36614 u=user n=ansible | shutdown complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_info This issue requires further information. Please answer any outstanding questions.
Projects
None yet
Development

No branches or pull requests

2 participants