FreeKB - Getting Started with the ansible-playbook command
Ansible - Getting Started with the ansible-playbook command

This assumes you have installed Ansible and have gone through our Getting Started with Ansible article.

The ansible-playbook command can can be used to perform a number of different tasks. By default, the ansible-playbook command is located at /usr/bin/ansible-playbook on Linux. The -v or --version option can be used to list the version of Ansible Playbook, the location of the Ansible configuration file, and the version of Python.

ansible-playbook --version

  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/your_username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible playbook module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, mm dd yyyy, hh:mm:ss) [GCC 4.8.5 yyyymmdd (Red Hat 4.8.5-39)]



The ansible-playbook command uses a .yml or .yaml file to perform a series of tasks, thus you'll need to create the .yml or .yaml file before issuing the ansible-playbook command. Check out our article on creating your first playbook .yml or .yaml file.

A playbook can be executed using this command.

ansible-playbook playbook.yml -i inventory.yml


The following should be returned. Check out this article if you want to know what Gathering Facts is all about.

PLAY [all]

TASK [Gathering Facts]
ok: []
ok: []
ok: []
ok: []

TASK [ping test]
ok: []
ok: []
ok: []
ok: []

PLAY RECAP : ok=2  changed=0  unreacable=0  failed=0 : ok=2  changed=0  unreacable=0  failed=0 : ok=0  changed=0  unreacable=1  failed=0 : ok=2  changed=0  unreacable=0  failed=0


Indentation matters in playbooks. For example, this will not work, as it does not have the expected indentation.

- hosts: all
 - debug: msg="improper indentation"


This will work, as it has the proper indentation.

- hosts: all
    - debug: msg="proper indentation"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 32793 in the box below so that we can be sure you are a human.