Posts in: February 1st, 2016


Ansible – A “hello world” Playbook

Playbooks are written in yaml format, and you can actually choose where to store your playbooks. In my case I’ll create a folder called “playbooks” for storing my playbooks, and I’ll create this in the root user’s home directory:

 

[root@controller ~]# pwd
/root
[root@controller ~]# mkdir playbooks
[root@controller ~]# cd playbooks
[root@controller playbooks]# pwd
/root/playbooks

In this directory, I’ll then create the following file:

 

[root@controller playbooks]# cat HelloWorld.yml
---
- name: This is a hello-world example
  hosts: ansibleclient01.local
  tasks:
  - name: Create a file called '/tmp/testfile.txt' with the content 'hello world'.
    copy: 
      content: "hello world\n" 
      dest: /tmp/testfile.txt

This playbook is designed to create the file “/tmp/testfile.txt” on the client ansibleclient01.local using ansible’s copy module.

 

You can think of this playbook as a