coglinev3.ansible_container
Ansible角色:ansible_container
这个角色与Ansible-Bender一起使用,以构建容器,包含:
- Ansible,
- OpenSSH和
- Systemd或Init V。
这些容器可以像虚拟机一样使用,例如用于通过GitHub操作测试Ansible角色。
此角色支持的Linux发行版有:
- Alpine Linux 3.12,
- Alpine Linux 3.13,
- Alpine Linux 3.14,
- Alpine Linux 3.15,
- Alpine Linux 3.16,
- Alpine Linux 3.17,
- Alpine Linux 3.18,
- Alpine Linux 3.19,
- Amazon Linux 2023,
- Debian 10 (Buster),
- Debian 11 (Bullseye),
- Debian 12 (Bookworm),
- Enterprise Linux 7,
- Enterprise Linux 8,
- Enterprise Linux 9,
- Fedora 34,
- Fedora 35,
- Fedora 36,
- Fedora 37,
- Fedora 38,
- Fedora 39,
- Ubuntu 18.04 LTS (Bionic Beaver),
- Ubuntu 20.04 LTS (Focal Fossa)和
- Ubuntu 22.04 LTS (Jammy Jellyfish)。
需求
如果你想使用这个角色来创建新的容器映像,你需要 ansible-bender。你可以通过我的Galaxy角色coglinev3.ansible_bender来安装ansible-bender。
角色变量
可用的变量如下所示,以及默认值(请参见defaults/main.yml):
# 是否使用sudo
ansible_container_become: true
# 安装包的状态:缺少 | 存在 | 最新
ansible_container_package_state: latest
# Debian的需求
ansible_container_requirements:
- libssl-dev
- libffi-dev
- openssh-server
- python3-apt
- python3-pip
- python3-setuptools
- python3-software-properties
- python3-wheel
- systemd
- sudo
# 强制新的Ansible配置文件 /etc/ansible/ansible.cfg
ansible_container_force_config: "no"
# 强制新的Ansible清单文件 /etc/ansible/hosts
ansible_container_force_inventory: "no"
# 定义Ansible用户和组
ansible_container_user: ansible
ansible_container_group: ansible
# Ansible配置文件ansible.cfg的一些变量
#
# 强制启用颜色模式,即使在没有TTY或“nocolor”设置为True时
ansible_config_force_color: true
# 控制解释器发现行为:
ansible_config_interpreter_python: auto
依赖
无。
示例剧本
在虚拟机上独立测试此角色的剧本
---
# 文件:roles/ansible_container/tests/test.yml
- hosts: localhost
remote_user: root
roles:
- { role: coglinev3.ansible_container }
vars:
ansible_container_become: true
使用ansible-bender创建带有Ansible和Systemd的CentOS 7镜像的剧本
---
- name: 带有ansible的CentOS 7容器化版本
hosts: all
vars:
# 针对ansible-bender的特定配置
ansible_bender:
base_image: centos:7
target_image:
# 调用容器时默认运行的命令
cmd: /usr/sbin/init
name: centos:7-ansible
labels:
build-by: "Cogline.v3"
volumes:
- /sys/fs/cgroup
tasks:
- name: 包含角色ansible_container
include_role:
name: ansible_container
vars:
ansible_container_become: false
新的容器映像通过以下命令构建:
ansible-bender build ./playbook.yml
版本
发布:1.17.0
许可证
BSD
作者信息
版权所有 © 2024 Cogline.v3。