Modules in Playbook

Using modules in Playbooks.

Create a playbook hostname putting into the file, its more interesting in this

Let's create a playbook, add a line-infile.yml file,


[ansible@ansible1 ~]$ vi addline-infile.yml

---

- hosts: database

tasks:

- name: create file if doesnot exist

file:

state: touch

path: /home/ansible/hostname.conf

- name: if line not there the add it.

lineinfile:

state: present

dest: /home/ansible/hostname.conf

line: Hostname={{ansible_hostname}}


I have used hosts as the database server, I have used module add the line in the file,

I have created two tasks,

• One is if the file is not found in that directory to create that

• Second in line to add HOSTNAME in that file


Let's run the playbook,

[ansible@ansible1 ~]$ ansible-playbook addline-infile.yml

The playbook runs exactly !!!

Go to the target server to check that file found or not,

The file has been created and the line has been added hostname correctly !!!!




Relevant Blogs:

Ansible Modules  

Ansible Custom facts 

Nagios threshold configuration 

chef adding nodes

Recent Comments

No comments

Leave a Comment