SSH Keys and DNS Resolution
In this lesson, you will learn about setting up DNS entries and SSH key authentication for Ansible-managed nodes. By the end of this lesson, you will be able to create DNS entries in the hosts file for your managed nodes and Ansible controller, generate an SSH key pair, deploy it to your managed nodes, and verify SSH connectivity from the Ansible controller to the managed nodes.
Setting Up DNS Entries
DNS (Domain Name System) resolution is crucial for network communication. In many cases, especially in test environments, you might need to manually set up DNS entries. We'll start by adding entries to the /etc/hosts file on the Ansible controller for managed-node-1, managed-node-2, and the ansible-controller itself.
Open the /etc/hosts file on the Ansible controller with a text editor. You will need root or sudo privileges to edit this file:
nano /etc/hosts
Now add the following to at the bottom of your hosts file:
Save the file and exit the editor. This allows us to use the name managed-node-1 instead of remembering and typing its IP address, 192.168.1.200. It will come in handy later!
Creating an SSH Key Pair
SSH keys provide a secure way of logging into a server without using a password. Let's generate an SSH key pair on the Ansible controller. Run the following command to generate an SSH key pair:bash
ssh-keygen -t rsa -b 4096
When prompted, you can press Enter to use the default file location. Optionally, set a passphrase for additional security.
Deploying the SSH Key
Next, we'll deploy the public key to managed-node-1 and managed-node-2. This will allow the Ansible controller to SSH into these nodes without a password. We will use the ssh-copy-id command to copy the public key to each managed node. Replace username with the actual username on the managed nodes:
__
Re…
No comments yet. Add the first comment to start the discussion.