maritza05
3/13/2018 - 3:16 AM

Making ping with ansible example

Example of how to make ping ans solve the problem: import zipfile\r\nImportError: No module named zipfile, "msg": "MODULE FAILURE"

Setup ansible with lxc

One of the steps in a tutorial said that it was needed to install python-minimal in order for being able of manage the servers, but this later shows the error when trying to connect to the server.

Managing keys

The first step actually is to share your public key with the server, this way the server will know who you are. You can create your key with the following steps:

  • Create the key with this:
ssh-keygen -t rsa -b 4096

Where the flags and their arguments are optional.

  • Now, in the directory ~/.ssh there must be your private key: id_rsa and your public key id_rsa.pub. Your private key it's only yours, and you can share your public key with the servers, here is where your public key actually enters in the game, the private key allows you to probe that you are the guy that the servers know. But first you need to share your public key with the servers this way:
ssh-copy-id sammy@your_server_ip

This command will add your public key to the ~/.ssh/authorized_keys file. You can do this manually, but the following steps are needed:

  • Copy thr content of your public key, you can see the content with:
cat ~/.ssh/id_rsa.pub
  • Login to the server.
  • Create the ~/.ssh directory and give it permissons
cat ~/.ssh/id_rsa.pub
chmod 700 ~/.ssh
  • Create an authorized_keys inside this directory and paste your key.
  • If you want, you can restrict the permissions to the file:
chmod 600 ~/.ssh/authorized_keys

Python and the Machines

The zipfile error was because the installation of python through python-minimal didn't install this package, one way to solve this is install the package or install the complete python.

Ping Pong

Now you can make a ping to know if you can reach the server:

ansible <ip> -m ping -u <user> <-i hosts>