Skip to content

Commit

Permalink
Fixed Issue #24
Browse files Browse the repository at this point in the history
  • Loading branch information
malavolti committed Feb 6, 2020
1 parent e53cb55 commit b4ca422
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 0 deletions.
9 changes: 9 additions & 0 deletions roles/memcached/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# defaults file for memcached

memcached_port: 11211
memcached_listen_ip: '0.0.0.0'
memcached_memory_limit: 512M
memcached_connections: 1024
memcached_log_file: /var/log/memcached.log
memcached_log_verbosity: "-vv"
9 changes: 9 additions & 0 deletions roles/memcached/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# handlers file for memcached

- name: "Restart memcached"
service:
name: memcached
state: restarted
when:
- not memcached_install.changed
53 changes: 53 additions & 0 deletions roles/memcached/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.4

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

15 changes: 15 additions & 0 deletions roles/memcached/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
# tasks file for memcached

# Include variables and define needed variables.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
tags: memcached

- name: "Install Memcached"
import_tasks: memcached-install.yml
tags: memcached

- name: "Configure Memcached"
import_tasks: memcached-configure.yml
tags: memcached
16 changes: 16 additions & 0 deletions roles/memcached/tasks/memcached-configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# Configure Memcached

- name: "Define memcached_user"
set_fact:
memcached_user: "{{ __memcached_user }}"
when: memcached_user is not defined

- name: "Copy Memcached configuration"
template:
src: memcached-{{ ansible_os_family }}.conf.j2
dest: "{{ memcached_config_file }}"
owner: "root"
group: "root"
mode: 0644
notify: "Restart memcached"
19 changes: 19 additions & 0 deletions roles/memcached/tasks/memcached-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# Install tasks

- name: "Run 'apt-get update' if the last one is more than 3600 seconds ago"
apt:
update_cache: yes
cache_valid_time: 3600

- name: "Install Memcached"
package:
name: memcached
state: present
register: memcached_install

- name: "Ensure Memcached is started and set to run on startup"
service:
name: memcached
state: started
enabled: yes
43 changes: 43 additions & 0 deletions roles/memcached/templates/memcached-Debian.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# {{ ansible_managed }}
# memcached default config file
# 2003 - Jay Bonci <jaybonci@debian.org>
# This configuration file is read by the start-memcached script provided as
# part of the Debian GNU/Linux distribution.

# Run memcached as a daemon. This command is implied, and is not needed for the
# daemon to run. See the README.Debian that comes with this package for more
# information.
-d

# Log memcached's output to /var/log/memcached
logfile {{ memcached_log_file }}
{{ memcached_log_verbosity }}

# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m {{ memcached_memory_limit }}

# Default connection port is 11211
-p {{ memcached_port }}

# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u {{ memcached_user }}

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l {{ memcached_listen_ip }}

# Limit the number of simultaneous incoming connections. The daemon default is 1024
-c {{ memcached_connections }}

# Lock down all paged memory. Consult with the README and homepage before you do this
# -k

# Return error when memory is exhausted (rather than removing items)
# -M

# Maximize core file limit
# -r
2 changes: 2 additions & 0 deletions roles/memcached/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions roles/memcached/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- memcached
4 changes: 4 additions & 0 deletions roles/memcached/vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

__memcached_user: memcache
memcached_config_file: /etc/memcached.conf
2 changes: 2 additions & 0 deletions roles/memcached/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for memcached

0 comments on commit b4ca422

Please sign in to comment.