Skip to content

Common Ansible Errors

Common Ansible error messages and solutions#

Failed to lock apt for exclusive operation#

failed: [default] => {"failed": true} msg: Failed to lock apt for exclusive operation

Solution#

apt needs elevated permissions.

Add become: yes to the top of the playbook:

- hosts: webserver
  become: yes
  tasks:
    - name: Updates apt cache
      action: apt update_cache=true

No package matching is available#

failed: [default] => (item=XXXXX) => {"failed": true, "item": "XXXXX"}
msg: No package matching 'XXXXX' is available

Solution#

That package does not exist in the configured repositories. It is usually a typo or a missing version suffix.

Eg. php-mysql might need to be php5-mysql on an older distribution.

Unknown host key when using the git module#

failed: [default] => {"failed": true}
msg: XXXXX.co.za has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module

Solution#

Add the host key manually before running the playbook, or use the module option that accepts the host key if that is appropriate for the environment.

Template error: expected token end of print statement#

fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! template error while templating string: expected token 'end of print statement', got 'key'"}

This is usually an issue with a variable containing a space.

ssh_pub_key={{ public key }}

Should be:

ssh_pub_key={{ public_key }}

Sources#