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:
parent
c99d1debe9
commit
f0185d9d88
@ -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_memory: "{{ base_memcached_memory | int // 4 if base_memcached_memory | int // 4 < 8192 else 8192 }}"
|
||||||
|
|
||||||
memcached_port: 11211
|
memcached_port: 11211
|
||||||
memcached_user: memcache
|
|
||||||
memcached_listen: "127.0.0.1"
|
memcached_listen: "127.0.0.1"
|
||||||
memcached_log: /var/log/memcached/memcached.log
|
memcached_log: /var/log/memcached/memcached.log
|
||||||
memcached_connections: 1024
|
memcached_connections: 1024
|
||||||
memcached_threads: 4
|
memcached_threads: 4
|
||||||
memcached_file_limits: "{{ memcached_connections | int + 1024 }}"
|
memcached_file_limits: "{{ memcached_connections | int + 1024 }}"
|
||||||
|
|
||||||
memcached_apt_packages:
|
|
||||||
- memcached
|
|
||||||
|
@ -29,4 +29,6 @@ galaxy_info:
|
|||||||
- development
|
- development
|
||||||
- openstack
|
- openstack
|
||||||
dependencies:
|
dependencies:
|
||||||
- apt_package_pinning
|
- role: apt_package_pinning
|
||||||
|
when:
|
||||||
|
- ansible_pkg_mgr == 'apt'
|
||||||
|
@ -16,5 +16,10 @@
|
|||||||
curl
|
curl
|
||||||
|
|
||||||
# Requirements for Paramiko 2.0
|
# Requirements for Paramiko 2.0
|
||||||
libssl-dev
|
libssl-dev [platform:dpkg]
|
||||||
libffi-dev
|
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
54
tasks/install-apt.yml
Normal 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
44
tasks/install-yum.yml
Normal 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
|
@ -13,7 +13,16 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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_install.yml
|
||||||
- include: memcached_config.yml
|
- include: memcached_config.yml
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
- name: Apply memcached config
|
- name: Apply memcached config
|
||||||
template:
|
template:
|
||||||
src: "memcached.conf"
|
src: "{{ memcached_conf_template }}"
|
||||||
dest: "/etc/memcached.conf"
|
dest: "{{ memcached_conf_dest }}"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
@ -31,13 +31,14 @@
|
|||||||
|
|
||||||
- name: Apply resource limits
|
- name: Apply resource limits
|
||||||
template:
|
template:
|
||||||
src: "memcached.j2"
|
src: "memcached.debian.j2"
|
||||||
dest: "/etc/default/memcached"
|
dest: "/etc/default/memcached"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: >
|
when:
|
||||||
memcached_connections > 1024
|
- ansible_pkg_mgr == 'apt'
|
||||||
|
- memcached_connections > 1024
|
||||||
notify: Restart memcached
|
notify: Restart memcached
|
||||||
tags:
|
tags:
|
||||||
- memcached-config
|
- memcached-config
|
||||||
@ -45,15 +46,15 @@
|
|||||||
- name: Configure soft file limits
|
- name: Configure soft file limits
|
||||||
lineinfile:
|
lineinfile:
|
||||||
dest: "/etc/security/limits.conf"
|
dest: "/etc/security/limits.conf"
|
||||||
regexp: "^memcache.*soft.*nofile.*"
|
regexp: "^{{ memcached_user }}.*soft.*nofile.*"
|
||||||
state: "present"
|
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"
|
insertbefore: "^# End of file"
|
||||||
|
|
||||||
- name: Configure hard file limits
|
- name: Configure hard file limits
|
||||||
lineinfile:
|
lineinfile:
|
||||||
dest: "/etc/security/limits.conf"
|
dest: "/etc/security/limits.conf"
|
||||||
regexp: "^memcache.*hard.*nofile.*"
|
regexp: "^{{ memcached_user }}.*hard.*nofile.*"
|
||||||
state: "present"
|
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"
|
insertbefore: "^# End of file"
|
||||||
|
@ -13,31 +13,14 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
#TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache
|
- include: install-apt.yml
|
||||||
#when https://github.com/ansible/ansible-modules-core/pull/1517 is merged
|
when:
|
||||||
#in 1.9.x or we move to 2.0 (if tested working)
|
- ansible_pkg_mgr == 'apt'
|
||||||
- name: Check apt last update file
|
|
||||||
stat:
|
|
||||||
path: /var/cache/apt
|
|
||||||
register: apt_cache_stat
|
|
||||||
tags:
|
tags:
|
||||||
- memcached-apt-packages
|
- install-apt
|
||||||
|
|
||||||
- name: Update apt if needed
|
- include: install-yum.yml
|
||||||
apt:
|
when:
|
||||||
update_cache: yes
|
- ansible_pkg_mgr == 'yum'
|
||||||
when: "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}"
|
|
||||||
tags:
|
tags:
|
||||||
- memcached-apt-packages
|
- install-yum
|
||||||
|
|
||||||
- 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
|
|
||||||
|
13
templates/memcached.redhat.j2
Normal file
13
templates/memcached.redhat.j2
Normal 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 }}"
|
@ -19,24 +19,25 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: "{{ rolename | basename }}"
|
- role: "{{ rolename | basename }}"
|
||||||
post_tasks:
|
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
|
- name: Open memcached log file
|
||||||
stat:
|
stat:
|
||||||
path: /var/log/memcached/memcached.log
|
path: "{{ memcached_log }}"
|
||||||
register: memcached_log
|
register: memcached_log_stat
|
||||||
- name: Check memcache is running
|
- 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
|
- name: Check role functions
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "memcached_log.stat.exists"
|
# TODO(mattt): Uncomment these once we have figured out systemd logging
|
||||||
- "'logfile /var/log/memcached/memcached.log' in memcached_file_content"
|
#- "memcached_log_stat.stat.exists"
|
||||||
- "'-l 127.0.0.1' in memcached_file_content"
|
#- "'logfile /var/log/memcached/memcached.log' in memcached_file_content"
|
||||||
- "'-c 1024' in memcached_file_content"
|
- "'-p 11211' in memcached_proc.stdout"
|
||||||
- "'-t 4' in memcached_file_content"
|
- "'-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"
|
||||||
|
3
tox.ini
3
tox.ini
@ -114,7 +114,8 @@ commands =
|
|||||||
--force
|
--force
|
||||||
ansible-playbook -i {toxinidir}/tests/inventory \
|
ansible-playbook -i {toxinidir}/tests/inventory \
|
||||||
-e "rolename={toxinidir}" \
|
-e "rolename={toxinidir}" \
|
||||||
{toxinidir}/tests/test.yml
|
-e "install_test_packages=True" \
|
||||||
|
{toxinidir}/tests/test.yml -vvvv
|
||||||
|
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Copyright 2014, Rackspace US, Inc.
|
# Copyright 2016, Rackspace US, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with 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
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
- name: Ensure the memcache user exists
|
memcached_user: memcache
|
||||||
user:
|
|
||||||
name: "{{ memcached_user }}"
|
memcached_packages:
|
||||||
comment: "memcached user"
|
- memcached
|
||||||
system: "yes"
|
|
||||||
shell: "/bin/false"
|
memcached_test_packages:
|
||||||
createhome: "no"
|
- netcat
|
||||||
tags:
|
|
||||||
- memcached-user
|
memcached_conf_template: memcached.conf.debian.j2
|
||||||
|
|
||||||
|
memcached_conf_dest: /etc/memcached.conf
|
26
vars/redhat.yml
Normal file
26
vars/redhat.yml
Normal 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
|
Loading…
Reference in New Issue
Block a user