Skip to content

Instantly share code, notes, and snippets.

@AlexMikhalev
Last active May 13, 2020 09:51
Show Gist options
  • Save AlexMikhalev/3aca3a5a0560c4d542692015bf6016d5 to your computer and use it in GitHub Desktop.
Save AlexMikhalev/3aca3a5a0560c4d542692015bf6016d5 to your computer and use it in GitHub Desktop.
Docker based ansible playbook to deploy Redis
---
- hosts: all
become: true
vars:
create_containers: 1
default_container_name: redis
default_container_image: redislabs/redismod
default_container_command: /usr/etc/redis/redis.conf
tasks:
- name: Install aptitude using apt
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
- name: Install required system packages
apt: name={{ item }} state=latest update_cache=yes
loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools']
- name: Add Docker GPG apt Key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker Repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu bionic stable
state: present
- name: Update apt and install docker-ce
apt: update_cache=yes name=docker-ce state=latest
- name: Install pip
apt: name=python-pip state=present
- name: Install Docker Module for Python
pip:
name: docker
- name: create directory if they don't exist
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: 0775
with_items:
- /usr/etc
- /usr/etc/redis
- /mnt/data
- name: Copy Redis Config
template:
src: redis.conf.j2
dest: /usr/etc/redis/redis.conf
owner: root
group: root
mode: 0644
become: true
- name: select zerotier interface
debug:
msg: "{{ ansible_zthnhhgvoc.ipv4.address }}"
- name: Pull default Docker image
docker_image:
name: "{{ default_container_image }}"
source: pull
- name: Deploy Redis Server
docker_container:
name: "{{ default_container_name }}"
image: "{{ default_container_image }}"
command: "{{ default_container_command }}"
network_mode: host
exposed_ports:
- 6379
ports:
- 6379:6379
volumes:
- /mnt/data:/data
- /usr/etc/:/usr/etc
state: started
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment