├── .ansible-lint ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── release.yml │ └── stale.yml ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md ├── defaults └── main.yml ├── handlers └── main.yml ├── meta └── main.yml ├── molecule └── default │ ├── converge.yml │ └── molecule.yml ├── tasks └── main.yml ├── templates ├── memcached-Debian.conf.j2 └── memcached-RedHat.conf.j2 └── vars ├── Debian.yml └── RedHat.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - 'yaml' 3 | - 'role-name' 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | --- 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: "30 3 * * 3" 10 | 11 | defaults: 12 | run: 13 | working-directory: 'geerlingguy.memcached' 14 | 15 | jobs: 16 | 17 | lint: 18 | name: Lint 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out the codebase. 22 | uses: actions/checkout@v4 23 | with: 24 | path: 'geerlingguy.memcached' 25 | 26 | - name: Set up Python 3. 27 | uses: actions/setup-python@v5 28 | with: 29 | python-version: '3.x' 30 | 31 | - name: Install test dependencies. 32 | run: pip3 install yamllint 33 | 34 | - name: Lint code. 35 | run: | 36 | yamllint . 37 | 38 | molecule: 39 | name: Molecule 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | distro: 44 | - rockylinux9 45 | - ubuntu2004 46 | 47 | steps: 48 | - name: Check out the codebase. 49 | uses: actions/checkout@v4 50 | with: 51 | path: 'geerlingguy.memcached' 52 | 53 | - name: Set up Python 3. 54 | uses: actions/setup-python@v5 55 | with: 56 | python-version: '3.x' 57 | 58 | - name: Install test dependencies. 59 | run: pip3 install ansible molecule molecule-plugins[docker] docker 60 | 61 | - name: Run Molecule tests. 62 | run: molecule test 63 | env: 64 | PY_COLORS: '1' 65 | ANSIBLE_FORCE_COLOR: '1' 66 | MOLECULE_DISTRO: ${{ matrix.distro }} 67 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow requires a GALAXY_API_KEY secret present in the GitHub 3 | # repository or organization. 4 | # 5 | # See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy 6 | # See: https://github.com/ansible/galaxy/issues/46 7 | 8 | name: Release 9 | 'on': 10 | push: 11 | tags: 12 | - '*' 13 | 14 | defaults: 15 | run: 16 | working-directory: 'geerlingguy.memcached' 17 | 18 | jobs: 19 | 20 | release: 21 | name: Release 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Check out the codebase. 25 | uses: actions/checkout@v4 26 | with: 27 | path: 'geerlingguy.memcached' 28 | 29 | - name: Set up Python 3. 30 | uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.x' 33 | 34 | - name: Install Ansible. 35 | run: pip3 install ansible-core 36 | 37 | - name: Trigger a new import on Galaxy. 38 | run: >- 39 | ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} 40 | $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) 41 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Close inactive issues 3 | 'on': 4 | schedule: 5 | - cron: "55 23 * * 6" # semi-random time 6 | 7 | jobs: 8 | close-issues: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | steps: 14 | - uses: actions/stale@v8 15 | with: 16 | days-before-stale: 120 17 | days-before-close: 60 18 | exempt-issue-labels: bug,pinned,security,planned 19 | exempt-pr-labels: bug,pinned,security,planned 20 | stale-issue-label: "stale" 21 | stale-pr-label: "stale" 22 | stale-issue-message: | 23 | This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 24 | 25 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 26 | close-issue-message: | 27 | This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 28 | stale-pr-message: | 29 | This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 30 | 31 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 32 | close-pr-message: | 33 | This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 34 | repo-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | .cache 5 | 6 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | line-length: 6 | max: 120 7 | level: warning 8 | 9 | ignore: | 10 | .github/workflows/stale.yml 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: Memcached 2 | 3 | [![CI](https://github.com/geerlingguy/ansible-role-memcached/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-memcached/actions/workflows/ci.yml) 4 | 5 | An Ansible Role that installs Memcached on RedHat/CentOS or Debian/Ubuntu Linux. 6 | 7 | ## Requirements 8 | 9 | None. 10 | 11 | ## Role Variables 12 | 13 | Available variables are listed below, along with default values (see `defaults/main.yml`): 14 | 15 | memcached_user: memcache 16 | 17 | The user under which the Memcached daemon will run. 18 | 19 | memcached_port: 11211 20 | memcached_listen_ip: 127.0.0.1 21 | 22 | The port and IP address (127.0.0.1 for localhost) on which Memcached will listen for requests. 23 | 24 | memcached_threads: 4 25 | 26 | Number of threads to run. 27 | 28 | memcached_memory_limit: 64 29 | memcached_max_item_size: 1m 30 | memcached_connections: 1024 31 | 32 | Memcached limits. The maximum amount of RAM `memcached` will consume (64MB is the default), the memory-limit of a single item and the maximum number of simultaneous connections memcached will handle. 33 | 34 | memcached_log_file: /var/log/memcached.log 35 | 36 | The location of the memcached log file. 37 | 38 | memcached_log_verbosity: "" 39 | 40 | Normally memcached does not log anything. Change to "-v" to enable logging or to "-vv" for debug logging. 41 | 42 | ## Dependencies 43 | 44 | None. 45 | 46 | ## Example Playbook 47 | 48 | - hosts: cache 49 | roles: 50 | - { role: geerlingguy.memcached } 51 | 52 | ## License 53 | 54 | MIT / BSD 55 | 56 | ## Author Information 57 | 58 | This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 59 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | memcached_port: 11211 3 | memcached_listen_ip: 127.0.0.1 4 | 5 | memcached_memory_limit: 64 6 | memcached_connections: 1024 7 | 8 | memcached_log_file: /var/log/memcached.log 9 | memcached_log_verbosity: "" 10 | 11 | memcached_max_item_size: 1m 12 | 13 | memcached_threads: 4 14 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart memcached 3 | service: name=memcached state=restarted 4 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: [] 3 | 4 | galaxy_info: 5 | role_name: memcached 6 | author: geerlingguy 7 | description: Memcached for Linux 8 | company: "Midwestern Mac, LLC" 9 | license: "license (BSD, MIT)" 10 | min_ansible_version: 2.10 11 | platforms: 12 | - name: Ubuntu 13 | versions: 14 | - precise 15 | - trusty 16 | - xenial 17 | - bionic 18 | - name: Debian 19 | versions: 20 | - all 21 | galaxy_tags: 22 | - web 23 | - database 24 | - memcached 25 | - keyvalue 26 | - kv 27 | - cache 28 | - caching 29 | - performance 30 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | pre_tasks: 7 | - name: Update apt cache. 8 | apt: update_cache=yes cache_valid_time=600 9 | when: ansible_os_family == 'Debian' 10 | 11 | roles: 12 | - role: geerlingguy.memcached 13 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | role_name_check: 1 3 | dependency: 4 | name: galaxy 5 | options: 6 | ignore-errors: true 7 | driver: 8 | name: docker 9 | platforms: 10 | - name: instance 11 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest" 12 | command: ${MOLECULE_DOCKER_COMMAND:-""} 13 | volumes: 14 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 15 | cgroupns_mode: host 16 | privileged: true 17 | pre_build_image: true 18 | provisioner: 19 | name: ansible 20 | playbooks: 21 | converge: ${MOLECULE_PLAYBOOK:-converge.yml} 22 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Include variables and define needed variables. 3 | - name: Include OS-specific variables. 4 | include_vars: "{{ ansible_os_family }}.yml" 5 | 6 | - name: Define memcached_user. 7 | set_fact: 8 | memcached_user: "{{ __memcached_user }}" 9 | when: memcached_user is not defined 10 | 11 | # Setup/install tasks. 12 | - name: Update apt cache. 13 | apt: update_cache=yes cache_valid_time=86400 14 | when: ansible_os_family == 'Debian' 15 | 16 | - name: Install Memcached. 17 | package: name=memcached state=present 18 | register: memcached_install 19 | 20 | # Configure Memcached. 21 | - name: Copy Memcached configuration. 22 | template: 23 | src: memcached-{{ ansible_os_family }}.conf.j2 24 | dest: "{{ memcached_config_file }}" 25 | owner: root 26 | group: root 27 | mode: 0644 28 | notify: restart memcached 29 | 30 | - name: Ensure Memcached is started and set to run on startup. 31 | service: name=memcached state=started enabled=yes 32 | -------------------------------------------------------------------------------- /templates/memcached-Debian.conf.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | # memcached default config file 3 | # 2003 - Jay Bonci 4 | # This configuration file is read by the start-memcached script provided as 5 | # part of the Debian GNU/Linux distribution. 6 | 7 | # Run memcached as a daemon. This command is implied, and is not needed for the 8 | # daemon to run. See the README.Debian that comes with this package for more 9 | # information. 10 | -d 11 | 12 | # Threads count 13 | -t {{ memcached_threads }} 14 | 15 | # Log memcached's output to /var/log/memcached 16 | logfile {{ memcached_log_file }} 17 | {{ memcached_log_verbosity }} 18 | 19 | # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default 20 | # Note that the daemon will grow to this size, but does not start out holding this much 21 | # memory 22 | -m {{ memcached_memory_limit }} 23 | 24 | # Default connection port is 11211 25 | -p {{ memcached_port }} 26 | 27 | # Run the daemon as root. The start-memcached will default to running as root if no 28 | # -u command is present in this config file 29 | -u {{ memcached_user }} 30 | 31 | # Specify which IP address to listen on. The default is to listen on all IP addresses 32 | # This parameter is one of the only security measures that memcached has, so make sure 33 | # it's listening on a firewalled interface. 34 | {% if memcached_listen_ip is string %} 35 | -l {{ memcached_listen_ip }} 36 | {% else %} 37 | {% for ip in memcached_listen_ip %} 38 | -l {{ ip }} 39 | {% endfor %} 40 | {% endif %} 41 | 42 | # Limit the number of simultaneous incoming connections. The daemon default is 1024 43 | -c {{ memcached_connections }} 44 | 45 | # Lock down all paged memory. Consult with the README and homepage before you do this 46 | # -k 47 | 48 | # Return error when memory is exhausted (rather than removing items) 49 | # -M 50 | 51 | # Maximize core file limit 52 | # -r 53 | 54 | -I {{ memcached_max_item_size }} 55 | -------------------------------------------------------------------------------- /templates/memcached-RedHat.conf.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | # Default connection port is 11211 3 | PORT="{{ memcached_port }}" 4 | 5 | # The user to run memcached as. 6 | USER="{{ memcached_user }}" 7 | 8 | # Limit the number of simultaneous incoming connections. The daemon default is 1024. 9 | MAXCONN="{{ memcached_connections }}" 10 | 11 | # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default 12 | # Note that the daemon will grow to this size, but does not start out holding this much 13 | # memory 14 | CACHESIZE="{{ memcached_memory_limit }}" 15 | 16 | # Extra options: 17 | # -l Specify which IP address to listen on. The default is to listen on all IP addresses 18 | # This parameter is one of the only security measures that memcached has, so make sure 19 | # it's listening on a firewalled interface. 20 | OPTIONS="{% if memcached_listen_ip is string %}-l {{ memcached_listen_ip }} {% else %}{% for ip in memcached_listen_ip %}-l {{ ip }} {% endfor %}{% endif %}-t {{ memcached_threads }} -I {{ memcached_max_item_size }} {{ memcached_log_verbosity }} >> {{ memcached_log_file }} 2>&1" 21 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __memcached_user: memcache 3 | memcached_config_file: /etc/memcached.conf 4 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __memcached_user: memcached 3 | memcached_config_file: /etc/sysconfig/memcached 4 | --------------------------------------------------------------------------------