Ansible Inventory Variables – ansible_ssh_executable with Examples
Ansible’s versatility as an IT automation tool comes from its myriad of configuration options. These parameters are typically specified in the Ansible inventory file, which outlines Ansible’s relationship with its managed hosts. One such key variable is
ansible_ssh_executable. In this post, we’ll explore the
ansible_ssh_executable variable and provide examples of how it can be used.
ansible_ssh_executable variable allows the user to specify a custom SSH executable. This can be useful if you need to use a specific version of SSH or a different SSH-based connection utility to connect to a host.
Defining ansible_ssh_executable in the Inventory File
ansible_ssh_executable, you need to define it in your inventory file. The format is
alias ansible_host=your_actual_host ansible_user=your_user ansible_ssh_executable=your_executable_path. Here’s an example:
Example with SSH Executable
Let’s say you have a server with the IP address
192.168.1.100, and you want Ansible to connect as the user
deploy using a custom SSH executable located at
/usr/local/bin/myssh. Here’s how you would define this in your inventory file:
my_server ansible_host=192.168.1.100 ansible_user=deploy ansible_ssh_executable=/usr/local/bin/myssh
In this case, Ansible will use the
/usr/local/bin/myssh executable to establish the SSH connection to
Using ansible_ssh_executable in a Playbook
ansible_ssh_executable is defined in your inventory file, Ansible will use this custom SSH executable when connecting to the host. Here’s a simple playbook as an example:
- hosts: my_server
- name: Check disk usage
command: df -h
When you run this playbook, Ansible will connect to
192.168.1.100) as the
deploy user using the specified custom SSH executable (
/usr/local/bin/myssh) and execute the
df -h command.
ansible_ssh_executable inventory variable offers the ability to specify a custom SSH executable, granting Ansible further flexibility to meet your specific automation requirements. As you dive deeper into Ansible’s capabilities, using these inventory variables can help to tailor your automation tasks effectively.