Page cover

Create hosts file

In this How To I will show you how to create a hosts file for your ansiblearrow-up-right server. Ansiblearrow-up-right is all about it’s file structure. Much like Linux, Ansiblearrow-up-right performs it’s tasks based on files. These files are set in a specific folder structure, to run playbooksarrow-up-right on specific hostsarrow-up-right. These hosts are determined by the “hosts file”. The hosts file will at minimum contain a hostname or IP address of a target device Ansiblearrow-up-right want’s to manage. In this demo I will be using VSCODEarrow-up-right and will have ansiblearrow-up-right version 2.9.2 running on my Ubuntuarrow-up-right machine. I will also show you how to add a host to your /etc/hosts file on your Ubuntuarrow-up-right machine. This file will do DNS resolution for your hosts that Ansiblearrow-up-right will manage. This is essential because Ansiblearrow-up-right uses SSHarrow-up-right to connect to the managed host. SSHarrow-up-right also must be installed on your machine. It also goes without saying that your machine must be able to PING the host Ansiblearrow-up-right will manage.

Instructions

In this demonstration i will use a 7200 series router in GNS3arrow-up-right connected to my Ubuntuarrow-up-right machine through a GNS3 arrow-up-rightNATarrow-up-right cloud appliance.

  • First obtain the IP address and hostname of the device you wish to manage. In this example I am using the Cisco CLIarrow-up-right to obtain the information needed.

GNS3 Network Diagram
Show run command to get IP address
  • Document the hostname and IP address of the host you want to manage. We are going to create the hosts file on our Ansible Server terminal using VIM.

vim command to create a file
inserting the hosts IP address for ansible connectivity
  • Leave the documentation up. We’ll need the info for the next step. Open up the /etc/hosts using your editor of choice. In this file we will put the hostname and IP address. This file will enable your machine to do a name resolution for the hostname and IP address you input. You will need this record in the /etc/hosts file to SSHarrow-up-right via hostname.

using VIM to edit the /etc/hosts file
using SSH to connect to our router
  • Now that we have successfully made an SSHarrow-up-right connection to our hosts, let’s open up VSCODEarrow-up-right, open the correct folder to our workspace, and create a hosts file!

open up VSCODE
opening our working repository

If you want to reference an Ansiblearrow-up-right repo check out my git repo’s here! ansiblearrow-up-right

Last updated