SSH Setup for Ansible

SSH Setup for Ansible

Ansible uses SSH for most interactions with managed servers so you need to configure and test SSH for every additional managed server you add to your inventory. The three steps below assume that you are following along with the CentOS 7 Minimal Install article and have created the SSH key as described in the Ansible Control System for ISAM article.

  • Copy the ansible SSH public key to the authorized_hosts file.
  • SSH to the remote system.
  • Configure passwordless sudo
  • Test the ansible inventory file

Copy the SSH public key

Use the ssh-copy-id command to copy the ansible user’s public key from the Ansible Control server to the new managed server.

ssh-copy-id command output

Passwordless sudo

Passwordless sudo is accomplished either at the group or user level. To keep it simple, I configure this for the wheel group but you can do this for any group or individual users by following the instructions at https://linux-tips.com/t/passwordless-sudo/150.

SSH to the new managed server and run the visudo command.

If you have followed the instructions for the CentOS 7 Minimal Install, the ansible user will already be in the wheel group so the only thing you need to do is enable passwordless login for the group by commenting out the default entry and enabling the nopasswd option a few lines below:

Enable passwordless sudo for the wheel group.

Save the file and exit the ssh session.

Exit the ssh session.
Finished with passwordless sudo.

Test the ansible connection.

Add the new host to your inventory file (sample.yml for the tutorials) and run the ansible ping command.

Ansbile ping command
Ansible ping command

And there you have it, the server is ready for management.

About Post Author

Kevin Jeffery

Kevin has worked in the Services, Utilities and Finance Industries in IT Architecture, Administration and Process Design, and Software Development. With over 20 years of experience in Information Technology, Kevin currently works as a Cyber Security Consultant specializing in IAM deployment and operations automation.

Leave Comments