Actually I did not learn this today but already some years ago. Sometimes I need to connect to remote servers that have no hosts-file or dns-entry. But I don’t want to remember IP-addresses!
Luckily I do have these servers defined in Ansible’s hosts-file and I could theoretically get the ip-address from there. However there’s an easier way: ansible-ssh. This is a shell-script that combines ansible-inventory
with ssh to allow something like this:
user@work$ cat hosts | grep server1
server1 ansible_host=192.168.0.1 ansible_user=root ansible_port=2222
user@work$ cat ansible.cfg | grep ssh_args
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
user@work$ ansible-ssh server1
ssh_args: -C -o ControlMaster=auto -o ControlPersist=60s
ansible_host: 192.168.0.1
ansible_user: root
ansible_port: 2222
ansible_ssh_common_args:
result command: ssh ubuntu@192.168.0.1 -C -o ControlMaster=auto -o ControlPersist=60s -p 2222
Top comments (0)