This tutorial will help you to install Ansible on Debian 9 (Stretch) systems.

Step 1 – Configure SSH Access

You can configure key based ssh for the remote Linux Ansible hosts. So password will not be required for SSH. Ansible also allows you to use a password for ssh, but key-based ssh is more secure. Generate a ssh key pair on your Ansible server: Copy the public key to all your remote hosts you need to connect via this ssh key.

Step 2 – Install Ansible on Debian 9

Ansible provides its official PPA for the installation on Debian systems. Add the following line to /etc/apt/sources.list file: Then run the following commands to add signing key and install Ansible.

Step 3 – Configure Ansible Hosts & Groups

Your server is ready with Ansible for remote host management and automation. You can have a number of hosts you need and manage them with single Ansible server. Here you need to define your remote systems in Ansible hosts file (/etc/ansible/hosts). You can also make groups of hosts with similar types. Here you need to properly organize your hosts into groups. Groups are used for performing one task on all remote hosts defined under it. Edit Ansible hosts configuration file. For exmaple: Add your hosts and organize them with groups. A host can be added under multiple groups. The below image will help you to understand group and hosts under a group.

Single Host Vars Configuration

You need to define settings for your hosts. The host-specific file must be with the same name as host (eg: web-host1) under the host_vars directory. Add the SSH settings to this file for the web-host1.

In case you don’t have used Step 1 for the ssh connection for this host. You can also add one of the below methods to web-hosts1 configuration file for the authentication.

Group Vars Configuration

You can configure common variable settings of a Group under group configurations. The group file name must be same as the group name (eg: webservers) under group_vars directory. Add the common variables to this file used by all the hosts added under this group.

Step 4 – Test Ansible Setup

Your Ansible setup is ready for testing. To test all hosts connectivity using ping module like: To test connectivity for specific host or group of hosts You can also run a command using shell module. For example, test the free memory on web-host1. You can also perform the same task for a group. Just use group name instead of hostname.

How to Install Ansible on Debian 9  Stretch    TecAdmin - 13How to Install Ansible on Debian 9  Stretch    TecAdmin - 5How to Install Ansible on Debian 9  Stretch    TecAdmin - 64