Here are some steps you need to should take when setting up <a href="https://www.ansible.com/)">Ansible</a> for the first time.

<ul>
<li><a href="#Install_the_software">Install the software</a></li>
<li><a href="#Confirm_ssh_working">Confirm ssh working</a></li>
<li><a href="#Create_a_Inventory/Host_file">Create a Inventory/Host_file</a></li>
<li><a href="#Ansible_Ping">Ansible Ping</a></li>
<li><a href="#Create_a_playbook">Create a playbook</a></li>
<li><a href="#Confirm_the_YAML_is_valid">Confirm the YAML is valid</a></li>
<li><a href="#Confirm_the_syntax_is_valid">Confirm the syntax is valid</a></li>
<li><a href="#Confirm_everything_works_together">Confirm everything works together</a></li>
</ul>

<h3 id="Install_the_software">Install the software</h3>
First you need to <a href="https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html">install</a> the <a href="https://www.ansible.com/)">Ansible</a> software. On Fedora that is as simple as a <em>dnf install ansible</em>, or on debian <em>apt install ansible</em>.

<h3 id="Confirm_ssh_working">Confirm ssh working</h3>

Confirm that you can connect to the servers via ssh as you would normally.

<pre><code>ssh -i /home/my_user/.ssh/id_ed25519_pi my_user@192.168.0.1
ssh -i /home/my_user/.ssh/id_ed25519_pi your_username@192.168.1.2
</code></pre>

<h3 id="Create_a_Inventory/Host_file">Create a Inventory/Host file</h3>

Translate the ssh commands into a <a href="https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html">Inventory/Host</a> file. I am using a YAML in this example but other variants are available.

<pre><code>all:
  hosts:
    my_server:
      ansible_host: 192.168.0.1
    your_server:
      ansible_host: 192.168.1.2
      ansible_ssh_user: your_username
  vars:
    ansible_connection: ssh
    ansible_ssh_user: my_user
    ansible_ssh_private_key_file: /home/my_user/.ssh/id_ed25519_pi
</code></pre>

<h3 id="Ansible_Ping">Ansible Ping</h3>
Check that your server is up and reported correctly in your file by having <a href="https://www.ansible.com/)">Ansible</a> ping it. This should allow you to determine if at least there is a command and control connection available.

<pre><code>ansible --inventory-file my_inventory.yaml -m ping all
</code></pre>

This uses the group <em>all</em> and will ping all servers under it. The reply below shows a positive and negative response. 

<pre><code>my_server | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
your_server | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.1.2 port 22: No route to host",
    "unreachable": true
}
</code></pre>

The <em>msg</em> will give you a clue as to what is going wrong and you should try to ssh directly with the Ansible credentials again, and then try and ping using Ansible.
<pre><code>ansible --inventory-file my_inventory.yaml -m ping your_server
</code></pre>

Modify the Inventory file until you have managed to get a successful reply. 

<h3 id="Create_a_playbook">Create a playbook</h3>

Work on your playbook and verify that it is valid yaml.

<pre><code>---
- name: Test Ping
  hosts: all
  tasks:
  - action: ping
</code></pre>

<h3 id="Confirm_the_YAML_is_valid">Confirm the YAML is valid</h3>
If there is no reply all is good.
<pre><code>yamllint ~/my_example.yaml
</code></pre>

If there is no reply all is good. For your reference I will remove the <em>---</em> line and this is the response.
<pre><code>yamllint ~/my_example.yaml
/home/user/my_example.yaml
  1:1       warning  missing document start "---"  (document-start)
</code></pre>

<h3 id="Confirm_the_syntax_is_valid">Confirm the syntax is valid</h3>
Then verify that the playbook is sane
<pre><code>ansible-playbook --syntax-check ~/my_example.yaml
</code></pre>

If there is no reply all is good. For your reference I will remove the <em>hosts</em> line and this is the response.
<pre><code>ansible-playbook --syntax-check ~/my_example.yaml
ERROR! the field 'hosts' is required but was not set
</code></pre>

<h3 id="Confirm_everything_works_together">Confirm everything works together</h3>

After that you should be able to run the playbook using.

<pre><code>ansible-playbook --inventory-file my_inventory.yaml ~/my_example.yaml

PLAY [Test Ping] ***************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************
[WARNING]: Platform linux on host my_server is using the discovered Python interpreter at /usr/bin/python, but
future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [my_server]
fatal: [your_server]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.1.2 port 22: No route to host", "unreachable": true}

TASK [ping] ********************************************************************************************************
ok: [my_server]

PLAY RECAP *********************************************************************************************************
my_server                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
your_server                : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
</code></pre>
