geerlingguy/ansible-for-devops

Chapter 1, ssh config is being used

matej-vrba opened this issue · 0 comments

I'm sorry if this was already reported, but on page 6 the book mentions

If you’re not using port 22 for SSH on this server, you will need to add it to the address, like www.example.com:2222, since Ansible defaults to port 22 and won’t get this value from your ssh config file

Which I believe is not true. With this inventory file

[test]
127.0.1.1

and this in ~/.ssh/config

Host 127.*
	port 2222

When I run ansible -i inv test -m ping I get

127.0.1.1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 127.0.1.1 port 2222: Connection refused",
    "unreachable": true
}

One thing I noticed is that there is some sort of caching. If i remove the offending lines config from ssh config and use ansible it works as expected. After that if I re-add the two lines to ssh config ansible still uses the old, working port - example