ansible icon indicating copy to clipboard operation
ansible copied to clipboard

delegate_to is not working with connection local in 2.9.27-1.el8ae ansible version

Open ucanbaz1 opened this issue 1 year ago • 3 comments

Summary

I upgraded ansible version from ansible-2.9.9-1.el8 to ansible-2.9.27-1.el8ae then I got some failure.

I have a playbook and it contains these tasks:

- name: Test
  hosts: as_vms
  gather_facts: no
  tasks:

  - name: "Delegate to em1"
    delegate_to:                    "{{hostvars['em1'].ansible_host}}"
    vars:
       ansible_user:                 "{{hostvars['em1'].ansible_user}}"
       ansible_ssh_private_key_file: "{{hostvars['em1'].ansible_ssh_private_key_file}}"
       ansible_ssh_common_args:      "{{hostvars['em1'].ansible_ssh_common_args}}"
       ansible_become:               yes
       ansible_become_user:          root
       ansible_become_method:        su
       ansible_become_password:      "xxxx"
    shell: hostname

I am running the playbook like:

ansible-playbook -i /inv.yml --connection local test.yml

In previous version (ansible-2.9.9-1.el8) It can delegate to other vm. But in current version( ansible-2.9.27-1.el8ae) It could not delegates. Or delegates but it not runs shell command delageted vm. It run local

Output is:

TASK [Delegate to em1] ********************************************************************************************************************************************************************
task path: /var/mcp/raf/commissioning/common/test.yml:8
changed: [em2-> <vm1_IP>] => {"changed": true, "cmd": "hostname", "delta": "0:00:00.005769", "end": "2024-03-06 14:17:24.866824", "msg": "", "rc": 0, "start": "2024-03-06 14:17:24.861055", "stderr": "", "stderr_lines": [], "stdout": "em2", "stdout_lines": ["em2"]}
changed: [em2-> <vm1_IP>] => {"changed": true, "cmd": "hostname", "delta": "0:00:00.005706", "end": "2024-03-06 14:17:24.906771", "msg": "", "rc": 0, "start": "2024-03-06 14:17:24.901065", "stderr": "", "stderr_lines": [], "stdout": "em2", "stdout_lines": ["em2"]}

Issue Type

Bug Report

Component Name

ansible

Ansible Version

ansible [core 2.15.3]
python version = 3.11.2 (main, Sep 14 2023, 10:46:13) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
jinja version = 3.1.2

Configuration

ANSIBLE_NOCOLOR(/etc/ansible/ansible.cfg) = True
ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_GATHERING(/etc/ansible/ansible.cfg) = smart
DEFAULT_MODULE_PATH(/etc/ansible/ansible.cfg) = ['/var/mcp/raf/commissioning/common/library']
DEFAULT_MODULE_UTILS_PATH(/etc/ansible/ansible.cfg) = ['/var/mcp/raf/commissioning/module_utils']
DEFAULT_TIMEOUT(/etc/ansible/ansible.cfg) = 60
DISPLAY_SKIPPED_HOSTS(/etc/ansible/ansible.cfg) = False

CALLBACK:
========

default:
_______
display_skipped_hosts(/etc/ansible/ansible.cfg) = False

CONNECTION:
==========

paramiko_ssh:
____________
timeout(/etc/ansible/ansible.cfg) = 60

ssh:
___
reconnection_retries(/etc/ansible/ansible.cfg) = 3
timeout(/etc/ansible/ansible.cfg) = 60

OS / Environment

RHEL 8, CentOS

Steps to Reproduce


Expected Results

It should delegate to other vm and It should runs shell command in delegated vm.

Actual Results

[root@em2 ~]# ansible-playbook -i /var/mcp/raf/inv.yml --connection local /var/mcp/raf/commissioning/common/test.yml -vvv
ansible-playbook [core 2.15.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/var/mcp/raf/commissioning/common/library']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.11.2 (main, Sep 14 2023, 10:46:13) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /var/mcp/raf/inv.yml as it did not pass its verify_file() method
script declined parsing /var/mcp/raf/inv.yml as it did not pass its verify_file() method
Skipping empty key (hosts) in group (bm_vms)
Skipping empty key (hosts) in group (mas_vms)
Skipping empty key (hosts) in group (fpm_vms)
Skipping empty key (hosts) in group (pa_vms)
Parsed /var/mcp/raf/inv.yml inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test.yml *******************************************************************************************************************************************************************************************
1 plays in /var/mcp/raf/commissioning/common/test.yml

PLAY [Test] **************************************************************************************************************************************************************************************************
<1.1.1.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<1.1.1.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<1.1.1.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516 `" && echo ansible-tmp-1709726178.877603-2271571-137883112183516="` echo /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516 `" ) && sleep 0'
<1.1.1.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<1.1.1.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<1.1.1.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692 `" && echo ansible-tmp-1709726178.8939643-2271572-127391511911692="` echo /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692 `" ) && sleep 0'
<em1> Attempting python interpreter discovery
<1.1.1.1> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'python3.11'"'"'; command -v '"'"'python3.10'"'"'; command -v '"'"'python3.9'"'"'; command -v '"'"'python3.8'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<em2> Attempting python interpreter discovery
<1.1.1.1> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'python3.11'"'"'; command -v '"'"'python3.10'"'"'; command -v '"'"'python3.9'"'"'; command -v '"'"'python3.8'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<1.1.1.1> EXEC /bin/sh -c '/usr/bin/python3.11 && sleep 0'
<1.1.1.1> EXEC /bin/sh -c '/usr/bin/python3.11 && sleep 0'
Using module file /usr/lib/python3.11/site-packages/ansible/modules/command.py
Using module file /usr/lib/python3.11/site-packages/ansible/modules/command.py
<1.1.1.1> PUT /root/.ansible/tmp/ansible-local-227140290xirg3l/tmpi5lg_vcd TO /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692/AnsiballZ_command.py
<1.1.1.1> PUT /root/.ansible/tmp/ansible-local-227140290xirg3l/tmp2q5m64cy TO /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516/AnsiballZ_command.py
<1.1.1.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692/ /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692/AnsiballZ_command.py && sleep 0'
<1.1.1.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516/ /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516/AnsiballZ_command.py && sleep 0'
<1.1.1.1> EXEC /bin/sh -c '/usr/libexec/platform-python /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516/AnsiballZ_command.py && sleep 0'
<1.1.1.1> EXEC /bin/sh -c '/usr/libexec/platform-python /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692/AnsiballZ_command.py && sleep 0'
<1.1.1.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1709726178.8939643-2271572-127391511911692/ > /dev/null 2>&1 && sleep 0'
<1.1.1.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1709726178.877603-2271571-137883112183516/ > /dev/null 2>&1 && sleep 0'

TASK [Delegate to em1] ********************************************************************************************************************************************************************
task path: /var/mcp/raf/commissioning/common/test.yml:7
changed: [em2 -> 1.1.1.1] => {
    "changed": true,
    "cmd": "hostname",
    "delta": "0:00:00.006371",
    "end": "2024-03-06 14:56:19.404545",
    "invocation": {
        "module_args": {
            "_raw_params": "hostname",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "",
    "rc": 0,
    "start": "2024-03-06 14:56:19.398174",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "em2",
    "stdout_lines": [
        "em2"
    ]
}
changed: [em1 -> 1.1.1.1] => {
    "changed": true,
    "cmd": "hostname",
    "delta": "0:00:00.005286",
    "end": "2024-03-06 14:56:19.408619",
    "invocation": {
        "module_args": {
            "_raw_params": "hostname",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "",
    "rc": 0,
    "start": "2024-03-06 14:56:19.403333",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "em2",
    "stdout_lines": [
        "em2"
    ]
}

PLAY RECAP ***************************************************************************************************************************************************************************************************
em1                        : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
em2                        : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[root@em2 ~]#

Code of Conduct

  • [X] I agree to follow the Ansible Code of Conduct

ucanbaz1 avatar Mar 06 '24 12:03 ucanbaz1

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the component bot command.

ansibot avatar Mar 06 '24 21:03 ansibot

Please try and create a standalone reproducer with both the play and inventory you are using here. Please also try the latest version of Ansible as 2.9 is no longer supported.

needs_info

jborean93 avatar Mar 07 '24 19:03 jborean93

@ucanbaz1 This Issue is waiting for your response. Please respond or the Issue will be closed.

click here for bot help

ansibot avatar Mar 26 '24 08:03 ansibot

@ucanbaz1 You have not responded to information requests in this Issue so we will assume it no longer affects you. If you are still interested in this, please create a new Issue with the requested information.

click here for bot help

ansibot avatar Apr 09 '24 08:04 ansibot