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
Comments
Post a Comment