almaops.ct_redis

Ansible 角色:Redis 容器

此角色在目标主机上创建 Redis 容器。

要求

目标主机必须运行 Docker 引擎,并安装 Docker PIP 模块。

角色变量

完整的可用变量列表请参见 defaults/main.yml

网络设置

变量 默认值 描述
ct_redis_enable_ports true 控制默认 Redis 端口是否被代理的标志
ct_redis_bind_addr "127.0.0.1" Redis 容器绑定的 IP 地址
ct_redis_bind_port "6379" Redis 容器绑定的端口
ct_redis_bind_ct_port "6379" Redis 服务器绑定的端口
ct_redis_ct_ports_default [] 默认 Redis 端口代理到容器
如果 {{ ct_redis_enable_ports }}false,此列表为空
如果为 true,列表设置为 ["{{ ct_redis_bind_addr }}:{{ ct_redis_bind_port }}:{{ ct_redis_bind_ct_port }}"]
ct_redis_ct_ports_extra [] 用户定义的任意代理到容器的端口
ct_redis_ct_ports {{ ct_redis_ct_ports_default + ct_redis_ct_ports_extra }} 代理到容器的最终端口集
传递给 docker_container 模块的 ports 参数

卷设置

变量 默认值 描述
ct_redis_path_config_base /etc/ct_redis 放置自定义配置文件的目录
ct_redis_path_config_file {{ ct_redis_path_config_base }}/{{ ct_redis_ct_name }}.conf 配置文件名称,默认为容器的名称
ct_redis_path_ct_config_file /usr/local/etc/redis/redis.conf 容器内自定义配置的路径
ct_redis_path_data_base /srv/ct_redis 数据卷的基础目录
ct_redis_path_data_volume {{ ct_redis_path_data_base }}/{{ ct_redis_ct_name }} 挂载到容器的数据目录
ct_redis_path_ct_data /data 容器内的数据目录
ct_redis_ct_volumes_data ["{{ ct_redis_path_data_volume }}:{{ ct_redis_path_ct_data }}"] 数据目录挂载
ct_redis_ct_volumes_config [] 自定义配置挂载,
如果 {{ ct_redis_enable_custom_config }}true
值设置为 ["{{ ct_redis_path_config_file }}:{{ ct_redis_path_ct_config_file }}:ro"]
ct_redis_ct_volumes_extra [] 用户定义的任意挂载到容器,
格式为 ["/source:/dest"]
ct_redis_ct_volumes {{ ct_redis_ct_volumes_data + ct_redis_ct_volumes_config + ct_redis_ct_volumes_extra }} 最终挂载集,
传递给 docker_container 模块的 volumes 参数

自定义配置

该角色提供一个简单的标志,用于启用 Redis 容器的自定义配置文件。

变量 默认值 描述
ct_redis_enable_custom_config false 控制是否将自定义配置文件挂载到容器的标志
如果值设置为 true,则 {{ ct_redis_ct_volumes_config }}{{ ct_redis_ct_command_custom_config }} 的变量将从 vars 中覆盖,一旦启用,该 Redis 配置文件将从模板在目标主机上创建并挂载到容器,配置文件的路径将追加到容器的 CMD
ct_redis_cfg_extra {} 自定义配置模板的 Redis 配置参数的键值对

命令

变量 默认值 描述
ct_redis_ct_command_custom_config [] 容器内自定义配置文件的路径,将追加到容器的 CMD 中,
如果 {{ ct_redis_enable_custom_config }} 为 true,值设置为 ["{{ ct_redis_path_ct_config_file }}"]
ct_redis_ct_command_options [] 传递给 redis-server 可执行文件的用户定义的任意选项
ct_redis_ct_command {{ [\"redis-server\"] + ct_redis_ct_command_custom_config + ct_redis_ct_command_options }} 最终命令,作为 docker_container 模块的 command 参数传递给容器

依赖关系

无。

示例剧本

# 创建绑定到自定义 IP 地址和端口的 Redis 容器
- hosts:
    - redis_server
  become: true
  roles:
    - role: almaops.ct_redis
      ct_redis_bind_addr: "192.168.0.10"
      ct_redis_bind_port: "26379"

# 创建带有自定义配置的 Redis 容器,源自您自己的 redis.conf 模板
- hosts:
    - redis_server
  become: true
  roles:
    - role: almaops.ct_redis
      ct_redis_enable_custom_config: true
      ct_redis_template_config: "/path/to/custom/redis.conf.j2"

许可证

MIT

贡献者

Valentin Gostev

关于项目

Ansible role deploys Redis container

安装
ansible-galaxy install almaops.ct_redis
许可证
mit
下载
489
拥有者
Premium IT Consulting