Updated role using the Multi-Distro framework

This commit updates the memcached_server role to work on Trusty,
Xenial, and CentOS 7.

NOTES:

1. This role no longer creates the memcache user since both Ubuntu and
   CentOS already install a suitable user
2. We have temporarily disabled testing of the log file since CentOS and
   Xenial do not log to file
3. On Ubuntu we drop ulimits into /etc/defaults/memcached, we need to
   figure out how to do the equivalent on CentOS
4. We update tasks/memcached_config.yml to use the correct memcached
   user in limits.conf, however neither these limits or the ones in
   templates/memcached.debian.j2 actually seem to be taking effect.
   More work in an additional review will need to be done to clean this
   all up.

Implements: blueprint multi-platform-host

Change-Id: I4c32f3d60939615c5d0c6fb202e96aacb35ab9b4
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Matt Thompson 2016-02-12 15:37:27 +00:00
parent c99d1debe9
commit f0185d9d88
15 changed files with 205 additions and 68 deletions

View File

@ -29,12 +29,8 @@ base_memcached_memory: "{{ ansible_memtotal_mb | default(4096) }}"
memcached_memory: "{{ base_memcached_memory | int // 4 if base_memcached_memory | int // 4 < 8192 else 8192 }}"
memcached_port: 11211
memcached_user: memcache
memcached_listen: "127.0.0.1"
memcached_log: /var/log/memcached/memcached.log
memcached_connections: 1024
memcached_threads: 4
memcached_file_limits: "{{ memcached_connections | int + 1024 }}"
memcached_apt_packages:
- memcached

View File

@ -29,4 +29,6 @@ galaxy_info:
- development
- openstack
dependencies:
- apt_package_pinning
- role: apt_package_pinning
when:
- ansible_pkg_mgr == 'apt'

View File

@ -16,5 +16,10 @@
curl
# Requirements for Paramiko 2.0
libssl-dev
libffi-dev
libssl-dev [platform:dpkg]
libffi-dev [platform:dpkg]
libffi-devel [platform:rpm]
openssl-devel [platform:rpm]
# For selinux
libselinux-python [platform:rpm]

54
tasks/install-apt.yml Normal file
View File

@ -0,0 +1,54 @@
---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache
#when https://github.com/ansible/ansible-modules-core/pull/1517 is merged
#in 1.9.x or we move to 2.0 (if tested working)
- name: Check apt last update file
stat:
path: /var/cache/apt
register: apt_cache_stat
tags:
- memcached-apt-packages
- name: Update apt if needed
apt:
update_cache: yes
when: "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}"
tags:
- memcached-apt-packages
- name: Install apt packages
apt:
pkg: "{{ item }}"
state: present
register: install_packages
until: install_packages|success
retries: 5
delay: 2
with_items: "{{ memcached_packages }}"
tags:
- memcached-apt-packages
- name: Install apt packages for testing
apt:
pkg: "{{ item }}"
state: present
register: install_test_packages
until: install_test_packages|success
retries: 5
delay: 2
with_items: "{{ memcached_test_packages }}"
when: install_test_packages|bool

44
tasks/install-yum.yml Normal file
View File

@ -0,0 +1,44 @@
---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: yum clean all
command: "/usr/bin/yum clean all"
register: yum_clean
until: yum_clean | success
tags:
- memcache-yum-packages
- name: Install yum packages
yum:
pkg: "{{ item }}"
state: latest
register: install_yum_packages
until: install_yum_packages | success
retries: 5
delay: 2
with_items: "{{ memcached_packages }}"
tags:
- memcache-yum-packages
- name: Install yum packages for testing
yum:
pkg: "{{ item }}"
state: latest
register: install_yum_test_packages
until: install_yum_test_packages | success
retries: 5
delay: 2
with_items: "{{ memcached_test_packages }}"
when: install_test_packages|bool

View File

@ -13,7 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- include: memcached_pre_install.yml
- name: Gather variables for each operating system
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
- "{{ ansible_os_family | lower }}.yml"
tags:
- always
- include: memcached_install.yml
- include: memcached_config.yml

View File

@ -20,8 +20,8 @@
- name: Apply memcached config
template:
src: "memcached.conf"
dest: "/etc/memcached.conf"
src: "{{ memcached_conf_template }}"
dest: "{{ memcached_conf_dest }}"
owner: "root"
group: "root"
mode: "0644"
@ -31,13 +31,14 @@
- name: Apply resource limits
template:
src: "memcached.j2"
src: "memcached.debian.j2"
dest: "/etc/default/memcached"
owner: "root"
group: "root"
mode: "0644"
when: >
memcached_connections > 1024
when:
- ansible_pkg_mgr == 'apt'
- memcached_connections > 1024
notify: Restart memcached
tags:
- memcached-config
@ -45,15 +46,15 @@
- name: Configure soft file limits
lineinfile:
dest: "/etc/security/limits.conf"
regexp: "^memcache.*soft.*nofile.*"
regexp: "^{{ memcached_user }}.*soft.*nofile.*"
state: "present"
line: "memcache\tsoft\tnofile\t\t{{ memcached_file_limits }}"
line: "{{ memcached_user }}\tsoft\tnofile\t\t{{ memcached_file_limits }}"
insertbefore: "^# End of file"
- name: Configure hard file limits
lineinfile:
dest: "/etc/security/limits.conf"
regexp: "^memcache.*hard.*nofile.*"
regexp: "^{{ memcached_user }}.*hard.*nofile.*"
state: "present"
line: "memcache\thard\tnofile\t\t{{ memcached_file_limits }}"
line: "{{ memcached_user }}\thard\tnofile\t\t{{ memcached_file_limits }}"
insertbefore: "^# End of file"

View File

@ -13,31 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache
#when https://github.com/ansible/ansible-modules-core/pull/1517 is merged
#in 1.9.x or we move to 2.0 (if tested working)
- name: Check apt last update file
stat:
path: /var/cache/apt
register: apt_cache_stat
- include: install-apt.yml
when:
- ansible_pkg_mgr == 'apt'
tags:
- memcached-apt-packages
- install-apt
- name: Update apt if needed
apt:
update_cache: yes
when: "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}"
- include: install-yum.yml
when:
- ansible_pkg_mgr == 'yum'
tags:
- memcached-apt-packages
- name: Install apt packages
apt:
pkg: "{{ item }}"
state: present
register: install_packages
until: install_packages|success
retries: 5
delay: 2
with_items: "{{ memcached_apt_packages }}"
tags:
- memcached-apt-packages
- install-yum

View File

@ -0,0 +1,13 @@
# {{ ansible_managed }}
{% if debug | bool %}
{% set _verbosity = '-vvv' %}
{% else %}
{% set _verbosity = '-vv' %}
{% endif %}
PORT="{{ memcached_port }}"
USER="{{ memcached_user }}"
MAXCONN="{{ memcached_connections }}"
CACHESIZE="{{ memcached_memory }}"
OPTIONS="-l {{ memcached_listen }} -t {{ memcached_threads }} {{ _verbosity }}"

View File

@ -19,24 +19,25 @@
roles:
- role: "{{ rolename | basename }}"
post_tasks:
- name: Open memcached file
slurp:
src: /etc/memcached.conf
register: memcached_file
- name: Read files
set_fact:
memcached_file_content: "{{ memcached_file.content | b64decode }}"
- name: Open memcached log file
stat:
path: /var/log/memcached/memcached.log
register: memcached_log
path: "{{ memcached_log }}"
register: memcached_log_stat
- name: Check memcache is running
shell: ps auxfww | grep 'memcache'
command: pgrep -a memcached
register: memcached_proc
- name: Test connecting to memcache
shell: echo stats | nc -w5 127.0.0.1 11211
register: memcached_stats
- name: Check role functions
assert:
that:
- "memcached_log.stat.exists"
- "'logfile /var/log/memcached/memcached.log' in memcached_file_content"
- "'-l 127.0.0.1' in memcached_file_content"
- "'-c 1024' in memcached_file_content"
- "'-t 4' in memcached_file_content"
# TODO(mattt): Uncomment these once we have figured out systemd logging
#- "memcached_log_stat.stat.exists"
#- "'logfile /var/log/memcached/memcached.log' in memcached_file_content"
- "'-p 11211' in memcached_proc.stdout"
- "'-u {{ memcached_user }}' in memcached_proc.stdout"
- "'-l 127.0.0.1' in memcached_proc.stdout"
- "'-c 1024' in memcached_proc.stdout"
- "'-t 4' in memcached_proc.stdout"
- "'STAT pid' in memcached_stats.stdout"

View File

@ -114,7 +114,8 @@ commands =
--force
ansible-playbook -i {toxinidir}/tests/inventory \
-e "rolename={toxinidir}" \
{toxinidir}/tests/test.yml
-e "install_test_packages=True" \
{toxinidir}/tests/test.yml -vvvv
[testenv:linters]

View File

@ -1,5 +1,5 @@
---
# Copyright 2014, Rackspace US, Inc.
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -13,12 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Ensure the memcache user exists
user:
name: "{{ memcached_user }}"
comment: "memcached user"
system: "yes"
shell: "/bin/false"
createhome: "no"
tags:
- memcached-user
memcached_user: memcache
memcached_packages:
- memcached
memcached_test_packages:
- netcat
memcached_conf_template: memcached.conf.debian.j2
memcached_conf_dest: /etc/memcached.conf

26
vars/redhat.yml Normal file
View File

@ -0,0 +1,26 @@
---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
memcached_user: memcached
memcached_packages:
- memcached
memcached_test_packages:
- nc
memcached_conf_template: memcached.redhat.j2
memcached_conf_dest: /etc/sysconfig/memcached