How to check if a role was successful
Ansible can be ‘noisy’ and log a lot of information to the terminal when running. To determine if a role was successful or not, check for unreachable or failed tasks from the ‘PLAY RECAP’ at the end of ansible-playbooks execution. The following is an example of a successful recap:
PLAY RECAP *******************************************************************
10.1.11.28: ok=6 changed=2 unreachable=0 failed=0 skipped=0
rescued=0 ignored=0
Here it shows that 2 tasks changed something on the system at the IP address 10.1.11.28
, while 6 tasks did not need to change anything on the system.
Common errors to check for
Unable to parse X as an inventory source / no hosts matched
When running the command ansible-playbook
against a single host or IP specified with the -i
argument, there must be a trailing comma.
If one is not set at the end of the IP address, Ansible assumes that the parameter provided to
-i
is the name of a file to read the hosts from. See Ansible’s Documentation about Inventory File
Correct Example:
ansible-playbook -i 10.1.11.3, playbook.yml
Incorrect Example:
ansible-playbook -i 10.1.11.3 playbook.yml
UNREACHABLE! Failed to connect to the host via ssh
Check the IP or hostname you specified in the ansible-playbook
command is correct,
and check that the VM you are targeting is running and hasn’t crashed.
Within the ‘PLAY RECAP’ Ansible will list a task or set of tasks as unreachable if Ansible
was unable to resolve the hostname, or connect over ssh to the host.
PLAY RECAP **************************************************************
local: ok=0 changed=0 unreachable=1 failed=0 skipped=0
rescued=0 ignored=0
Authentication error
Ansible will parse the config.yml
file located next to the Playbook for Authentication information.
If the specified SSH private key, username, or password is incorrect, then Ansible will mark the host UNREACHABLE
and display an error on the first failed task "Gathering Facts". The message will specify more detail about the error.
Examples of failed authentication attempts:
TASK [Gathering Facts] ************************************************************
{"changed": false, "msg": "Failed to connect to the host via ssh:
Received disconnect from 192.168.1.31 port 22:2: Too many authentication failures\r
Disconnected from 192.168.1.31 port 22", "unreachable": true}
PLAY RECAP ***************************************************************************
192.168.1.31: ok=0 changed=0 unreachable=1 failed=0 skipped=0
rescued=0 ignored=0
TASK [Gathering Facts] ***********************************************************
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to
the host via ssh: ansible@localhost: Permission denied (publickey,password).",
"unreachable": true}
PLAY RECAP ***************************************************************
localhost: ok=0 changed=0 unreachable=1 failed=0 skipped=0
rescued=0 ignored=0
Be sure to configure the ansible_ssh_private_key_file
and ansible_user
fields within config.yml
correctly.
Additional Help
Increase the verbosity level of ansible-playbook
The verbosity of Ansible logging can be increased by passing multiple -v
arguments
while invoking the ansible-playbook
command. We recommend trying -v
to start, and -vvv
if more information is required.
When requesting help from c2games, please include command output using -vvv
.
Example:
ansible-playbook -i 10.1.11.3, playbook.yml -vvv