Install Ansible and Create Ansible Playbook for CRON
- Category : Linux Helpline (Easy Guide)
- Posted on : Feb 05, 2019
- Views : 3,172
- By : Radcliff S.
Ansible is a tool that used to manage various nodes from an ansible installed Controlling Machine using SSH Protocol. It makes every system administrative tasks more easy.
Ansible Playbook is a organised unit of scripts which is working in the Controller machine (Ansible installed system). Playbook are written in YAML format.
Install Ansible on Centos 7:-
Controller Machine IP:- 10.0.0.209
Node IP :- 10.0.0.206
10.0.0.207
* more ip can be used.
Step 1 :-
Install Ansible using yum in Controller Machine. Check the version of the installed Ansible.
# yum install ansible
# ansible --version
Step 2 :-
Setup Controlling Machine to connect node using ssh protocol.
Create ssh key to access node systems and copy the key to the node.
# ssh-keygen
# ssh-copy-id root@10.0.0.206
# ssh-copy-id root@10.0.0.207
Step 3:-
Add ips of node systems into the Inventory of Ansible by editing /etc/ansible/hosts .
# vim /etc/ansible/hosts
[ansi-test]
10.0.0.206
10.0.0.207
Note: Here both ip can call using name ansi-test
Step 4:-
Test Ansible in the Controller Machine by using below commands.
1. First of all test the Controlling Machine have ping with node system using ansible commands.
# ansible -m ping all
10.0.0.206 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.0.0.207 | SUCCESS => {
"changed": false,
"ping": "pong"
}
Now Lets start to work with Ansible Playbook.
Create Ansible Playbook for CRON :-
Our requirement is to take backup of /test folder to /backup folder at every day 12:00 in all the nodes that are configured to the controller machine with Ansible.
First make /test folder and /backup folder.
# mkdir /backup
# mkdir /test
Now we need to write a backup shell script in the folder /backup_script with the name backup.sh . This script are need to transfer all nodes.
# vim /backup_script/backup.sh
#!/bin/bash
tar vcf /backup/backup_test.`date +\%Y-\%m-\%d_\%H:\%M:\%S`.tar /test
Setup Ansible playbook and create yml script for cronjob :-
Make a directory Playbooks in side /etc/ansible.
# mkdir /etc/ansible/playbooks
Create cron.yml using vim tool.
# vim /etc/ansible/playbooks/cron.yml
tasks:
- name: Install a yum package in Ansible
yum:
name: crontabs
state: present
- name: copy the script into node systems
copy: src=/backup_script/backup.sh dest=/root/
- name: create a cron in node systems
cron:
name: "Backup Cron"
user: "root"
minute: 00
hour: 12
job: "/usr/bin/sh /root/backup.sh 2>&1"
Now we have created Ansible Playbook with name cron.yml. Execute the following command to run the script using Ansible.
# ansible-playbook /etc/ansible/playbooks/cron.yml
Categories
- cPanel Question 47
- cPanel Software Management 29
- cPanel Tutorials 13
- Development 29
- Domain 13
- General 19
- Linux Helpline (Easy Guide) 156
- Marketing 47
- MySQL Question 13
- News 2
- PHP Configuration 14
- SEO 4
- SEO 42
- Server Administration 84
- SSL Installation 54
- Tips and Tricks 24
- VPS 3
- Web Hosting 44
- Website Security 22
- WHM questions 13
- WordPress 148
Subscribe Now
10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!Archive Calendar
Sat | Sun | Mon | Tue | Wed | Thu | Fri |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Recent Articles
-
Posted on : Sep 17
-
Posted on : Sep 10
-
Posted on : Aug 04
-
Posted on : Apr 01
Tags
- ts
- myisam
- vpn
- sql
- process
- kill
- tweak
- server load
- attack
- ddos mitigation
- Knowledge
- layer 7
- ddos
- webmail
- DMARC
- Development
- nginx
- seo vpn
- Hosting Security
- wireguard
- innodb
- exim
- smtp relay
- smtp
- VPS Hosting
- cpulimit
- Plesk
- Comparison
- cpu
- encryption
- WHM
- xampp
- sysstat
- optimize
- cheap vpn
- php-fpm
- mariadb
- apache
- Small Business
- Error
- Networking
- VPS
- SSD Hosting
- Link Building
- centos
- DNS
- optimization
- ubuntu