You can use ansible command line (ad-hoc) to make small changes however the real power lies in it's scripting capabilities using playbooks.

Ansible playbooks are use in Puppet and Chef.

Puppet  → Module

Chef → Cookbook

Playbooks are divided into 3 sections:

  1. Targets Section - defines on which host(s) this playbook will be executed and how it will be executed.
    This will be done over ssh

  2. Variable Section (Optional) - defines your variables which can be used by the playbook.

  3. Task Section - List all the modules you intend to run.

Here is a sample playbook.

Note: proper indentation is very important.
playbook - test.yml

 - hosts: localhost
   user: john
    warningMsg: 'Welcome to this exciting time in your life.\nYou will never be the same\n'
   - name: Sample Task
      dest: /tmp/warning
      content: "{{ warningMsg }}"

This sample playbook will create a file on the defined host with the warning message defined.

To run this playbook simple issue the command: ansible-playbook <file.yml>

> ansible-playbook test.yml
[WARNING]: provided hosts list is empty, only localhost is available
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [Sample Task] *************************************************************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0


If you desire to run this script on a host besides localhost, you will need to ....


For a full list of modules that can be used with ansible, see


  • No labels