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

Strange behaviour when delegating to a host defined in a variable #11705

Closed
elmundio87 opened this Issue Jul 23, 2015 · 7 comments

Comments

Projects
None yet
8 participants
@elmundio87

elmundio87 commented Jul 23, 2015

ISSUE TYPE

Bug Report

COMPONENT NAME

core

ANSIBLE VERSION
1.9.1
CONFIGURATION

SSH connections are routed through a VM via a ProxyCommand

OS / ENVIRONMENT

Control Machine OS OSX 10.10.4
Managed OS CentOS 7

SUMMARY

When using a variable in a delegate_to, the connection hangs.

STEPS TO REPRODUCE

This doesn't work - it eventually times out.

- name: Wait for the server to come back
  wait_for:
    host: "{{ inventory_hostname }}"
    port: 22 
    state: started
  sudo: false
  delegate_to: "{{ ssh_delegate }}"

This works (using a hardcoded delegate host)

- name: Wait for the server to come back
  wait_for:
    host: "{{ inventory_hostname }}"
    port: 22 
    state: started
  sudo: false
  delegate_to: "10.128.0.100"

This also works (putting the variable into a with_items loop and referencing it in delegate_to)

- name: Wait for the server to come back
  wait_for:
    host: "{{ inventory_hostname }}"
    port: 22 
    state: started
  sudo: false
  delegate_to: "{{ item }}"
  with_items:
    - "{{ ssh_delegate }}"
EXPECTED RESULTS

I would expect all 3 examples to work the same way.

ACTUAL RESULTS

The first example fails

@rothgar

This comment has been minimized.

rothgar commented Jul 24, 2015

Also have this problem on 1.9.2 with the control host being rhel 7.1. Although for me the with_items trick doesn't work and manually specifying the host doesn't work.

using -vvv I can see the command is trying to run against the correct host but the $HOME/.ansible/tmp/ansible-tmp-* directory is never created.

I can see the remote user log into the delegated box but it doesn't appear the command is ever executed.

@rothgar

This comment has been minimized.

rothgar commented Jul 24, 2015

After re-running this multiple times I was able to get the normal delegate_to: "{{ remote_host }}" syntax working.

I had to remove the $HOME/.ansible/tmp folder and make sure my remote user was fully logged off of the delegated host pkill -KILL -u ansible_user

After deleting all traces of the old runs the delegated runs worked.

@vankhoa011

This comment has been minimized.

vankhoa011 commented Sep 28, 2015

Got same problem on Ansible 1.8.4. I tried all tricks but it didn't work.

Another person got same problem:
https://groups.google.com/forum/#!msg/ansible-project/SQjsIt5jORI/flH_9EJl458J

@jimi-c jimi-c removed the P3 label Dec 7, 2015

@soar

This comment has been minimized.

soar commented Jan 20, 2016

I can confirm this problem with Ansible 2.0 (stable-2.0 branch - 3840fb2).

For example, any reference like:

delegate_to: "{{ var_with_plaintext_inventory_hostname }}"

not works, but if it changed to:

delegate_to: "{{ item }}"
with_items: "{{ groups['inventory_group_name'] }}"

it works like a charm.

I've tried even tricks like:

delegate_to: "{{ hostvars[var_with_plaintext_inventory_hostname].inventory_hostname }}"

no ways. Only {{ item }} works.

@bcoca

This comment has been minimized.

Member

bcoca commented Mar 19, 2016

this might be solved by #15024

@gregorydulin

This comment has been minimized.

Contributor

gregorydulin commented Oct 12, 2017

I think this was fixed. My office is using delegate_to: "{{ remote_host }}" and delegate_to: "{{ item }}" extensively in Ansible 2.3, often while logged in to the target in a separate terminal (for troubleshooting), and haven't run into this issue yet.

@bcoca

This comment has been minimized.

Member

bcoca commented Oct 12, 2017

closing as per above

@bcoca bcoca closed this Oct 12, 2017

@ansibot ansibot added bug and removed bug_report labels Mar 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment