Ansible Playbook

USING A PLAYBOOK TO COPY A PROGRAM AND CUSTOMIZE IT FOR THE TARGET HOST
We are going to create a playbook to copy a program from the local server to the target servers.
Let's create a playbook,
Here I have used different variables,
• One is copy file from the local server has given path and destination path to past that file.
• Second is to add in that file “hostname”
• Third is a shell script to run that program in that file
Then create program1.sh file in local server,
In this file I have added hostname output, let's give permission access for this file,
let's run the playbook now,


[ansible@ansible1 ~]$ ansible-playbook mainapp1.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}}


Go and check the target server...


[ansible@ansible2 ~]$ ls


There is our program1.sh file found. It is given the exact output !!!


Relevant Blogs:

Ansible tower 

Ansible Variable 

Linux Containers (LXC) 

Zabbix agent installation and configuration


Recent Comments

No comments

Leave a Comment