After installing the ansible. Normally these was the two basic setup that made me stuck my ansible  playbook. Here, I have tried to sum up, what  are the issues that appears and how can we resolve it.

The ansible stuck in gathering facts:

when we first try to login to a instance for the first time we get a message like

Are you sure you want to continue connecting (yes/no)?

One way  to get  rid of it is manually  login to the instance and go through this process manually. But we are here for automations. So to get rid of it, we simply need to make one setting in ansible config files.

Ansible config file is available in this location /etc/ansible/ansible.cfg Here just need to uncomment this default setting, that is commented by default.

# uncomment this to disable SSH key host checking
host_key_checking = False

Ansible playbook can ssh

There  might be multiple reason for it but lets see what else it can be?

  1. Not added ssh public key:
    Make sure you  have added the ansible public key to the authorized_keys in the instance. With this we make the ansible server authorized to the instance. We can even automate this process of adding the public key. But I would not like to cover it here. If you are interested you will find a roles built for the purpose.
  2. If we are not able to ssh even after clearing the above issue. The problem can be we have not set the instance ip in the right location. If you have created the inventory.ini and you are trying to run playbook to the instance set in inventory.ini but not able to. We need to change the default ansible inventory location that is set to /etc/ansible/hosts

    Either change the host location in ansible.cfg or set the ip address to the default host location.

    #inventory      = /etc/ansible/hosts

    Change this to your newly created inventory.ini.

These are few of the issues that I used to face during my initial setups.