coglinev3.ansible_container
Ansible Role: ansible_container
This role is designed to work with Ansible-Bender for creating containers which include:
- Ansible,
- OpenSSH, and
- Systemd or Init V.
These containers act like virtual machines and are useful for testing Ansible roles, such as in GitHub actions.
The role supports the following Linux distributions:
- Alpine Linux versions 3.12 to 3.19,
- Amazon Linux 2023,
- Debian versions 10 (Buster) to 12 (Bookworm),
- Enterprise Linux versions 7 to 9,
- Fedora versions 34 to 39,
- Ubuntu 18.04 LTS (Bionic Beaver), 20.04 LTS (Focal Fossa), and 22.04 LTS (Jammy Jellyfish).
Requirements
To create new container images using this role, you need to install ansible-bender. You can get it through my galaxy role coglinev3.ansible_bender.
Role Variables
Here are the available variables along with their default values (see defaults/main.yml):
# Use sudo or not
ansible_container_become: true
# State for installed packages: absent | present | latest
ansible_container_package_state: latest
# Requirements for Debian
ansible_container_requirements:
- libssl-dev
- libffi-dev
- openssh-server
- python3-apt
- python3-pip
- python3-setuptools
- python3-software-properties
- python3-wheel
- systemd
- sudo
# Force a new Ansible configuration file /etc/ansible/ansible.cfg
ansible_container_force_config: "no"
# Force a new Ansible inventory file /etc/ansible/hosts
ansible_container_force_inventory: "no"
# Define an Ansible user and group
ansible_container_user: ansible
ansible_container_group: ansible
# Variables for Ansible configuration file ansible.cfg
# Forces color mode even without a TTY or when “nocolor” is True
ansible_config_force_color: true
# Control the interpreter discovery behavior:
ansible_config_interpreter_python: auto
Dependencies
There are no dependencies.
Example Playbooks
Playbook to test this role on a virtual machine
---
# file: roles/ansible_container/tests/test.yml
- hosts: localhost
remote_user: root
roles:
- { role: coglinev3.ansible_container }
vars:
ansible_container_become: true
Playbook to create a CentOS 7 image with Ansible and Systemd using ansible-bender
---
- name: Containerized version of CentOS 7 with ansible
hosts: all
vars:
# Configuration specific for ansible-bender
ansible_bender:
base_image: centos:7
target_image:
# Command to run by default when starting the container
cmd: /usr/sbin/init
name: centos:7-ansible
labels:
build-by: "Cogline.v3"
volumes:
- /sys/fs/cgroup
tasks:
- name: Include role ansible_container
include_role:
name: ansible_container
vars:
ansible_container_become: false
To build the new container image, run the following command:
ansible-bender build ./playbook.yml
Version
Release: 1.17.0
License
BSD
Author Information
Copyright © 2024 Cogline.v3.
Informazioni sul progetto
This role is used with Ansible-Bender to create Ansible Containers for CI/CD tests with Travis-CI.
Installa
ansible-galaxy install coglinev3.ansible_container
Licenza
bsd-3-clause
Download
6.5k
Proprietario