# Custom ssh\_config Not Working As Expected

**URL:** <https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [September 24, 2014, 1:27am UTC](https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316 "2014-09-24T01:27:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Goodhouse](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@James\_Goodhouse](https://forum.ansible.com/u/James_Goodhouse)\
**Post date:** [September 24, 2014, 1:27am UTC](https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316/1 "2014-09-24T01:27:30Z")

</div>

I am having some issues with a custom ssh\_config file and not sure if I’m doing something wrong, if it’s an ssh bug, or if it’s an Ansible bug.

I currently have a custom ssh\_config file placed next to my ansible.cfg file. In the ansible.cfg file I have the line ssh\_args = -F ssh\_config under the [ssh\_connection] section. Inside of my ssh\_config file is the following:

Host bastion  
HostName xxx.xxx.xxx.xxx  
User ubuntu  
Host app01

HostName xxx.xxx.xxx.xxx  
ProxyCommand ssh bastion nc %h %p  
User ubuntu

If I then run the command ssh app01 -F ssh\_config I receive the following error:

ssh: Could not resolve hostname bastion: nodename nor servname provided, or not known

However, if instead of referencing the ssh\_config file, I instead place the contents into ~/.ssh/config and run the command ssh app01, all is well and it is able to resolve the hostname, bastion.

Is there a setting I am missing somewhere or is this potentially a bug in either ssh or Ansible?

Thanks for your help and if you need any more info, please ask!

- James

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 1:55am UTC](https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316/2 "2014-09-24T01:55:50Z")

</div>

Could this possibly be because the CWD when executing ansible can’t find your specified ssh\_config ?

Maybe try fulling pathing it for starters?

---

<div class="post-metadata">

**Author:** ![James\_Goodhouse](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@James\_Goodhouse](https://forum.ansible.com/u/James_Goodhouse)\
**Post date:** [September 24, 2014, 8:19am UTC](https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316/3 "2014-09-24T08:19:30Z")

</div>

I tried fully pathing it to no avail. It seems to be picking up on the custom ssh\_config because if I change the ProxyCommand from ssh bastion nc %h %p to ssh ubuntu@x.x.x.x nc %h %p then it works fine. It’s almost like it’s not referencing the custom ssh\_config for the ProxyCommand and is defaulting back to looking in the config in ~/.ssh or /etc/ssh.

---

<div class="post-metadata">

**Author:** ![jorginator74](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@jorginator74](https://forum.ansible.com/u/jorginator74)\
**Post date:** [September 24, 2014, 8:20am UTC](https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316/4 "2014-09-24T08:20:27Z")

</div>

Hi

> I am having some issues with a custom ssh\_config file and not sure if I'm doing  
> something wrong, if it's an ssh bug, or if it's an Ansible bug.
> 
> I currently have a custom ssh\_config file placed next to my ansible.cfg file.  
> In the ansible.cfg file I have the line ssh\_args = -F ssh\_config under the  
> [ssh\_connection] section. Inside of my ssh\_config file is the following:
> 
> &nbsp;&nbsp;Host bastion  
> &nbsp;&nbsp;&nbsp;&nbsp;HostName xxx.xxx.xxx.xxx  
> &nbsp;&nbsp;&nbsp;&nbsp;User ubuntu  
> &nbsp;&nbsp;Host app01  
> &nbsp;&nbsp;&nbsp;&nbsp;HostName xxx.xxx.xxx.xxx  
> &nbsp;&nbsp;&nbsp;&nbsp;ProxyCommand ssh bastion nc %h %p  
> &nbsp;&nbsp;&nbsp;&nbsp;User ubuntu
> 
> If I then run the command ssh app01 -F ssh\_config I receive the following  
> error:
> 
> &nbsp;&nbsp;ssh: Could not resolve hostname bastion: nodename nor servname provided, or  
> not known
> 
> However, if instead of referencing the ssh\_config file, I instead place the  
> contents into ~/.ssh/config and run the command ssh app01, all is well and it  
> is able to resolve the hostname, bastion.

That makes sense.

When you run "ssh app01 -F ssh\_config", it will obviously use the  
given SSH config file.... But in order to connect to app01, it needs  
to run the ProxyCommand. But this will use the \*default\* ssh config  
file. Not the one in the current directory...

As far as SSH is concerned, the ProxyCommand is simply a shell  
command - even if it just invokes ssh...

---

<div class="post-metadata">

**Author:** ![James\_Goodhouse](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@James\_Goodhouse](https://forum.ansible.com/u/James_Goodhouse)\
**Post date:** [September 24, 2014, 7:28pm UTC](https://forum.ansible.com/t/custom-ssh-config-not-working-as-expected/16316/5 "2014-09-24T19:28:45Z")

</div>

Thanks for your reply, Karl!

So given that is the case, would there be a way for it to behave the way I’m expecting when using a custom ssh\_config file?

On a separate but related note, I’m trying to use a wildcard entry in my ssh\_config for various servers. So for example, my inventory file has the entry app01-stg ansible\_ssh\_host=10.0.11.195 and my ssh\_config file is as follows:

Host app\*-stg  
ProxyCommand ssh ubuntu@_._._._ nc %h %p  
User ubuntu

When I then run the command ansible all -m ping -i inventory/staging.ini -l app01-stg I receive the error app01-stg | FAILED =\> SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh. However, all works fine if I remove the ansible\_ssh\_host address from the inventory file and rerun the command with the following ssh\_config file:

Host app01-stg  
HostName 10.0.11.195  
ProxyCommand ssh ubuntu@_._._._ nc %h %p  
User ubuntu

Thanks in advance!!

- James
