Sample Ansible Playbook creation

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 a yaml file called HelloWorld.yml

---

 - hosts: all

   tasks:

   - name: Create a file called '/tmp/testfile.txt' with the content 'Hellow World-BRR'

     win_copy:

       content: hellow world-BRR

       dest: c:\temp\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 script that you can execute. You can execute this playbook using the ansible-playbook command:

PLAY [all] *******************************************************************************************************TASK [Gathering Facts] *******************************************************************************************************ok: [192.168.0.67]

TASK [Create a file called '/tmp/testfile.txt' with the content 'Hellow World-BRR'] *******************************************************************************************************changed: [192.168.0.67]

PLAY RECAP *******************************************************************************************************192.168.0.67               : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


This results in the following file being created on the client

ramana@AHTLPT42:~$ cd /mnt/c/temp

ramana@AHTLPT42:/mnt/c/temp$ ls
testfile.txt

ramana@AHTLPT42:/mnt/c/temp$ cat testfile.txt

Hello World-BRR

Comments

Popular posts from this blog

Email Sending through O365 using OAuth Protocol

IoT Technology

What is reverse proxy?