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

only set ansible_ssh_host if not already set #11663

Merged
merged 1 commit into from
Jul 27, 2015

Conversation

whereismyjetpack
Copy link

Issue Type:

Bugfix Pull Request

Ansible Version:

ansible 2.0.0 (devel 5b5ba35) last updated 2015/07/20 20:08:15 (GMT -400)

Ansible Configuration:

[defaults]
inventory = hosts.py (test script for this bug report)

Environment:

OS X

Summary:

When using dynamic inventory that sets ansible_ssh_host as a hostvar, ansible will set ansible_ssh_host = to ipv4_address, which earlier gets defaulted to name -- so, ansible will connect to 'name' instead of ansible_ssh_host

Steps To Reproduce:

set ansible.cfg to a dynamic hosts file. I made a super basic inventory script for testing. I've tested with both _meta vars, and hostvars supplied with --host
here is a sample script I used for testing:

#!/usr/bin/python
import json
import argparse

parser = argparse.ArgumentParser(description='test')
parser.add_argument('--list', action='store_true', default=False)
parser.add_argument('--host', action='store')
args = parser.parse_args()

inventory = {}

if args.list:
    inventory['all'] = {}
    inventory['all']['hosts'] = []
    inventory['all']['hosts'].append("bluefish")
    print json.dumps(inventory)
elif args.host:
    if args.host == 'bluefish':
        inventory['ansible_ssh_host'] = '192.168.1.4'
        inventory['ansible_ssh_port'] = '22'
    print json.dumps(inventory)


##### Expected Results:

     ansible bluefish -m ping -vvv                                                              
    <192.168.1.4> ESTABLISH SSH CONNECTION FOR USER: whereismyjetpack
    <192.168.1.4> EXEC ssh -C -tt -q -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/tmp/ansible-ssh-%h-%p-%r" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.4 mkdir -p "$HOME/.ansible/tmp/ansible-tmp-1437441884.36-23031124330564" && chmod a+rx "$HOME/.ansible/tmp/ansible-tmp-1437441884.36-23031124330564" && echo "$HOME/.ansible/tmp/ansible-tmp-1437441884.36-23031124330564"

##### Actual Results:

     ansible bluefish -m ping -vvv                                                       
    <bluefish> ESTABLISH SSH CONNECTION FOR USER: whereismyjetpack
    <bluefish> EXEC ssh -C -tt -q -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/tmp/ansible-ssh-%h-%p-%r" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 bluefish mkdir -p "$HOME/.ansible/tmp/ansible-tmp-1437441672.46-233732641996366" && chmod a+rx "$HOME/.ansible/tmp/ansible-tmp-1437441672.46-233732641996366" && echo "$HOME/.ansible/tmp/ansible-tmp-1437441672.46-233732641996366"

@bcoca bcoca added bugfix_pull_request P1 Priority 1 - Immediate Attention Required; Release Immediately After Fixed labels Jul 21, 2015
@bcoca bcoca added this to the v2 milestone Jul 21, 2015
@amenonsen
Copy link
Contributor

The commit and description make sense to me. I tried out the included hosts.py and can confirm that we try to connect to "bluefish" before and "192.168.1.4" after.

jimi-c added a commit that referenced this pull request Jul 27, 2015
only set ansible_ssh_host if not already set
@jimi-c jimi-c merged commit a1a8997 into ansible:devel Jul 27, 2015
@jimi-c
Copy link
Member

jimi-c commented Jul 27, 2015

Merged, thanks!

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. P1 Priority 1 - Immediate Attention Required; Release Immediately After Fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants