2 minutes
Automated with Ansible
Hello everyone !
In previous blog, I was share automation to the configuration virtual environment but we have spent time to do manual installation. So, to automation deployment we need Ansible to help us to do automation.
What exactly is Ansible ?
Actually, ansible is an open source software that automates software provisioning, configuration management, and application deployment. We will use ansible playbook to automate deployment. An ansible playbook is like blueprint that can automation task to send commands to remote computer in a scripted way. Normally, ansible uses YAML for playbook language.
Get Started
Open your terminal and execute :
sudo apt-get install ansible
There is two necessary components for ansible playbook
- Inventory (Where to deploy)
- Playbook (How to deploy)
Lets create playbook
Actually, playbook is step by step how to deploy our application to server.
Create the playbook file called playbook.yml, we could write like this:
- name: command in directory project
hosts: localhost
tasks:
- name: Export MySQL dump database
command: mysqldump -u alvin food_oms_db > food_oms_db.sql
- name: Bundle application with tar
command: tar --exclude='./.git' -zcvf build/build.tgz .
- name: Copy to VM local
command: scp -i /home/hafiztsalavin/generasi_gigih/virtualbox/private_key build.tgz vagrant@192.168.20.21:app
Name : it’s specify name of the step
Host : define where to execute the task, normally will be explained on inventory file
Task : it’s like what is the step? Its like procedure to be executed
Lets create inventory
Inventroy is like file that define target of our playbook and normaly inventory is consist of the ip/address of our machine target.
all:
hosts:
server01:
ansible_host: 192.168.20.1
all : it’s the global group include all hosts
hosts : it’s contain the list of host in this group
server01 : it’s name our instance as server01
ansible_host : it’s address of our machine
Execute playbook
And execute the playbook using:
ansible-playbook --inventory inventory.yml --user vagrant --private-key /home/hafiztsalavin/generasi_gigih/virtualbox/private_key playbook.yml
Tada, your application was deployed to server.
That’s it what can i share. With ansible we can easily a server setup, software installation and a lot more tasks.
Thankyou !!!