Ansible configuring target servers.

How to configure target servers in ansbile server.

Note: you must be able to connect to the target server/s without password.

  1. Simple way to generating and copying the ssh keys

You won’t be able to ssh the target server, before ssh keys.

Run below command on both (ansible and target) servers.

ssh-keygen

Below one is Ansible server.

Target server:

Now copy the pub key from Ansible server to authorised_keys in target server.

Ansible server: (Note: These were test servers and they are terminated after this exercise).

Note: you can use below command too.

cat ~/.ssh/id_rsa.pub | ssh username@remote_host “mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys”

Target server:

Once ssh keys are sorted you should be able to ssh the target server.

Adhoc command

At Ansible server, make sure you have entered the private ip of the all target servers and categorized them. Below are the examples.

ubuntu@ip-172-31-18-85:~$ ansible -i inventory all -m “shell” -a “touch Testdevops”

Now let’s confirm it has created a file Testdevops in target server.

Now let’s run first playbook.

Make sure you have entries of the server/s in inventory file. Also your ansible playbook is written correctly.

Let’s run playbook.

ansible-playbook -i inventory first-playbook.yml

Now let’s check if iginx is installed on the target server.

Leave a Reply

Your email address will not be published. Required fields are marked *