First Ansible Playbook

Ansible is a configuration management tool used by DevOps to automate the software installation and configuration process on any machine (node).

The following are the steps to run your first playbook (shown for Mac). Playbook is just a sequence of steps. This will run the playbook on your local host.

  1. Install Ansible
brew install ansible
  1. Open a file editor, type the following and save as myplaybook.yml
---
- name: "First Ansible playbook"
hosts: localhost
connection: local
tasks:

- name: "ls command"
shell: "ls"
register: "output"

- debug: var=output.stdout_lines
  1. Run the following command to run the playbook.
ansible-playbook myplaybook.yml

The output is shown as below.

PLAY [First Ansible playbook] **********************************************************************************

TASK [Gathering Facts] *****************************************************************************************
ok: [localhost]

TASK [ls command] **********************************************************************************************
changed: [localhost]

TASK [debug] ***************************************************************************************************
ok: [localhost] => {
    "output.stdout_lines": [
        "myplaybook.yml"
    ]
}

PLAY RECAP *****************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s