FreeKB - Ansible command - SSH
Ansible command - SSH

Home > Search


This assumes you have installed Ansible Tower and that you are familiar with the ansible command and that you've an inventory.yml file with one or more target servers. Let's say your inventory.yml file has the following.

---
all:
  children:
    hosts:
      server1.example.com:


Then, in a playbook.yml, you can perform tasks against every server in inventory.yml, like this.

- hosts: all

 

This will attempt to make an SSH connection to the servers in inventory.yml. If the target servers are configured to accept SSH connection via a public/private key pair, on your ansible server, enter the users hidden .ssh directory.

cd /home/JohnDoe/.ssh

 

In this example, ssh-keygen is used to create the public certificate and private key. The public certificate is named id_rsa.pub and the private key is id_rsa.

ssh-keygen -t rsa

 

Configure the .ssh directory so that only JohnDoe has read/write/execute permission, and configure the public/private key pair so that only JohnDoe has read/write permission.

chmod 700 /home/JohnDoe/.ssh
chmod 600 /home/JohnDoe/.ssh/id_rsa
chmod 600 /home/JohnDoe/.ssh/id_rsa.pub

 

The content of id_rsa.pub will be something like this (without the line breaks).

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqphOmkv0RPMn48EwCRED/eSSYsbyrRlxymWdEA/
rYuq4eqZAVzTYxJxnTuCTLnrr5hvVMYstcEnwFB+uXZut8UoCtOlrqA7gyy0EjdRh1qay1YXIbB
QZxpHDmAy9D3aSDoa5sVwrC1GQzNN4nH58pGnoGF+Df/A76LlZeBfmO1hP/a7hLIf8L+2o4LfKM
NBvqf37tlYDOKUA+mU+XSCmBbMk3/4UgYxuQ3HdE8w5RhFZf9Mbvb5GqubCy7N8zp6v/hRRfT0j
pWqR8kr2qauQttd9+q1n5pKCCjUO+/+jeLDdhtJ7Pls8O7motxJoNsqxKof1lJKvtt44VxYpdoY
K6w== JohnDoe@client

 

Copy the content of id_rsa.pub on the "client" machine and paste the content into the authorized keys file on the target server machine. In this example, the authorized_keys file would have the following (without the line breaks).

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqphOmkv0RPMn48EwCRED/eSSYsbyrRlxymWdEA/
rYuq4eqZAVzTYxJxnTuCTLnrr5hvVMYstcEnwFB+uXZut8UoCtOlrqA7gyy0EjdRh1qay1YXIbB
QZxpHDmAy9D3aSDoa5sVwrC1GQzNN4nH58pGnoGF+Df/A76LlZeBfmO1hP/a7hLIf8L+2o4LfKM
NBvqf37tlYDOKUA+mU+XSCmBbMk3/4UgYxuQ3HdE8w5RhFZf9Mbvb5GqubCy7N8zp6v/hRRfT0j
pWqR8kr2qauQttd9+q1n5pKCCjUO+/+jeLDdhtJ7Pls8O7motxJoNsqxKof1lJKvtt44VxYpdoY
K6w== JohnDoe@client

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter e05a8 in the box below so that we can be sure you are a human.




Comments