Skip to content
This repository has been archived by the owner on Jan 18, 2018. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vdvm committed Feb 12, 2015
0 parents commit 78ddf27
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Ansible Role: Memcached

Installs Memcached (latest)

## Supported platforms

```
CentOS 6 & 7
Ubuntu 14.04
```

## Requirements

None

## Role Variables

Start:

```
memcached_start: true
```

Start on boot:

```
memcached_start_on_boot: true
```

Listen address:

```
memcached_address: 127.0.0.1
```

Listen port:

```
memcached_port: 11211
```

Memory:

```
memcached_memory: 64
```

Max connections:

```
memcached_connections: 1024
```

## Dependencies

```
pcextreme.repo-epel
pcextreme.repo-pcextreme
```

## Example Playbook

```
- hosts: servers
roles:
- { role: pcextreme.memcached }
```

## License

MIT

## Author Information

Created by [Attila van der Velde](https://github.com/vdvm)
8 changes: 8 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
memcached_start: true
memcached_start_on_boot: true

memcached_address: 127.0.0.1
memcached_port: 11211
memcached_memory: 64
memcached_connections: 1024
3 changes: 3 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart memcached
service: name=memcached state=restarted
22 changes: 22 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
galaxy_info:
author: "Attila van der Velde"
description: "Installs Memcached (latest)"
company: "PCextreme B.V."
license: "license (MIT)"
min_ansible_version: 1.8
platforms:
- name: EL
versions:
- 6
- 7
- name: Ubuntu
versions:
- trusty
categories:
- system
- web

dependencies:
- { role: pcextreme.repo-epel }
- { role: pcextreme.repo-pcextreme }
10 changes: 10 additions & 0 deletions tasks/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Install service
yum: name=memcached enablerepo=epel state=present

- name: Update config
template: src=centos_memcached.j2 dest=/etc/sysconfig/memcached owner=root group=root mode=0644
notify: restart memcached

- name: Start and enable service
service: name=memcached state={{ 'started' if memcached_start else 'stopped' }} enabled={{ 'yes' if memcached_start_on_boot else 'no' }}
6 changes: 6 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- include: centos.yml
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version|int >= 6

- include: ubuntu.yml
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version == '14.04'
17 changes: 17 additions & 0 deletions tasks/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Update apt cache
apt: update_cache=yes cache_valid_time=900

- name: Install service
apt: pkg=memcached state=present

- name: Update config
template: src=ubuntu_memcached.j2 dest=/etc/default/memcached owner=root group=root mode=0644
notify: restart memcached

- name: Update config
template: src=ubuntu_memcached.conf.j2 dest=/etc/memcached.conf owner=root group=root mode=0644
notify: restart memcached

- name: Start and enable service
service: name=memcached state={{ 'started' if memcached_start else 'stopped' }} enabled={{ 'yes' if memcached_start_on_boot else 'no' }}
5 changes: 5 additions & 0 deletions templates/centos_memcached.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PORT="{{ memcached_port }}"
USER="memcached"
MAXCONN="{{ memcached_connections }}"
CACHESIZE="{{ memcached_memory }}"
OPTIONS="-l {{ memcached_address }}"
47 changes: 47 additions & 0 deletions templates/ubuntu_memcached.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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 /var/log/memcached.log

# Be verbose
# -v

# Be even more verbose (print client commands as well)
# -vv

# 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 }}

# 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 memcache

# 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_address }}

# 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
1 change: 1 addition & 0 deletions templates/ubuntu_memcached.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENABLE_MEMCACHED={{ 'yes' if memcached_start else 'no' }}

0 comments on commit 78ddf27

Please sign in to comment.