Installing Redis using Ansible Playbook on Ubuntu

Redis is a popular open source database server used for data storage, networked applications, and web applications. In this blog post, we will discuss the basics of Redis, its key features, and some of its applications.

Some time we need to automate the packages installation on multiple server, Here we are about to create Ansible Playbook to install Redis database server.

We believe, You have already installed Ansible if not you need to click on given link to install Ansible on ubuntu server.

https://www.techbeginner.in/2019/12/how-to-install-ansible-on-ubuntu.html

Step 1: Configure Ansible

By default ansible host configuration file is /etc/ansible/hosts Here you need to add the redis server details like this, Use the following step for the same, In my case i have 1 apache server.

Group Name – WebServer
IP Address – Your IP Address
Username – example
Password – XXXXXXXXXX

You need to add your server in ansible host file, Syntax is given below, You need to open the /etc/ansible/hosts file with nano or vim text editor.

sudo vim /etc/ansible/hosts

and add the web server entry like this.

[redis]
localhost ansible_connection=ssh ansible_ssh_user=ubuntu ansible_ssh_pass=xxxxxxx

Change the credentials as per your environment, Save and exit from the vim text editor and verify the host machine connectivity with ansible by using the given command.

ansible all -m ping

You should get output like this.

Here our host configuration is completed and now we can go for next step to write play book.

Step 2: Creating Redis Playbook

You need to create a redis-playbook.yml and you change it according to your requirement.

sudo vim redis-playbook.yml

Paste the given code.

- hosts: redis
  become: yes
  tasks:

    - name: Update
      apt: update_cache=yes   
   
    - name: Installing Redis
      apt: name=redis-server state=latest

      notify:
        - restart redis.service 

    - name: Restart Redis Server
      service: name=redis state=restarted enabled=yes

Now we are ready to use the Redis’s PlayBook, To execute the PlayBook you need to use the given command.

ansible-playbook redis-playbook.yml

You should get output like this.

Verify the Redis service on your targeted server by using the given command.

sudo systemctl status redis.service

Conclusion

We have successfully created ansible playbook for Redis Server in our Ubuntu 18.04 server.

Get connected with our new devops tools based website- https://www.devopstricks.in/

Installing Redis using Ansible Playbook on Ubuntu

4 thoughts on “Installing Redis using Ansible Playbook on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top