ansible_bender

Ansible Role: ansible_bender

Build GitHub tag (latest by date) License

Are you tired of building containers with Dockerfiles?

This role installs ansible-bender, a tool which bends containers using Ansible playbooks and turns them into container images.

With ansible-bender, you no longer have to build and configure containers differently than you do traditional virtual machines or bare-metal systems. You can now apply the power of Ansible and re-use your existing Ansible content for your containerized ecosystem. Use templates, copy files, drop in encrypted data, handle errors, add conditionals, and more. Everything Ansible brings to orchestrating your infrastructure can now be applied to the image build process.

The supported Linux distributions for this role are:

  • Alpine Linux 3.14,
  • Alpine Linux 3.15,
  • Alpine Linux 3.16,
  • Alpine Linux 3.17,
  • Alpine Linux 3.18,
  • Alpine Linux 3.19,
  • Enterprise Linux 8,
  • Enterprise Linux 9,
  • Debian 11 (Bullseye),
  • Debian 12 (Bookworm),
  • Linux Mint 20 (Ulyana),
  • Ubuntu 20.04 LTS (Focal Fossa),
  • Ubuntu 22.04 LTS (Jammy Jellyfish).

ΝOTE

The rootless mode for Podman requires the newuidmap program to be installed. Enterprise Linux 7 (RHEL 7 / CentOS 7) supports this only since version 7.7.


Requirements

Ansible-bender requires a few binaries to be present on your host system:

  • Buildah
  • Podman
  • Python 3.6 or later (python 3.5 or earlier are not supported and known not to be working)
  • Ansible (Ansible needs to be built against python 3)

All requirements are installed with this role.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):


# dependencies for ansible-bender (like buildah, podman and python3.6 or higher)
ab_dependencies:
  - buildah
  - podman
  - python3
  - python3-pip
  - python3-setuptools
  - python3-software-properties
  - python3-virtualenv
  - procps
  - runc
  - slirp4netns

# package state for dependencies: ( present ) | latest 
ab_dependencies_package_state: present

# Packages that are installed with the Python3 installer pip3.
ab_python_packges:
  - wheel
  - ansible
  - ansible-bender

# package state for python packages: ( present ) | latest
ab_python_packge_state: present

# comma separated list of container registries
ab_container_search_registry: "'docker.io', 'registry.fedoraproject.org', 'quay.io', 'registry.access.redhat.com', 'registry.centos.org'"

# a list of users which can use the rootless mode:
ab_users: []

Dependencies

None.

Example Playbook

---
# file: roles/ansible-bender/tests/test.yml

- hosts: all
  vars:
    ab_users:
      - your_username
  roles:
    - { role: coglinev3.ansible_bender }

Example how to use ansible-bender

Create an image

If you want to test ansible-bender, you first need an Ansible playbook. You can create a playbook template with:

ansible-bender init

Now open the playbook.yml file, change the ansible_bender dictionary variable and add some tasks. The following simple example playbook creates a nginx container based on Alpine Linux.

---
- name: Containerized version of nginx
  hosts: all
  vars:
    # configuration specific for ansible-bender
    ansible_bender:
      # ansible-bender needs an image with preinstalled Python 3 to work
      base_image: python:3-alpine
      target_image:
        # command to run by default when invoking the container
        cmd: "nginx -g \"daemon off;\""
        name: bender-nginx
        ports: ['80', '443']
        working_dir: /var/www/localhost/htdocs
        labels:
          build-by: "{{ ansible_user }}"
      working_container:
        volumes:
        # mount this git repo to the working container at /src
        - "{{ playbook_dir }}:/src:Z"
  tasks:
  - name: install dependencies needed to run project bender-nginx
    apk:
      name: nginx
      state: present
  - name: Ensure directory /run/nginx exists
    file:
      path: /run/nginx
      state: directory
      mode: '0750'
      owner: nginx
      group: nginx

And now you can build the example image with:

ansible-bender build ./playbook.yml

Run the container

After the image is successfully created you can start a new container with podman.

podman run -d -p 8080:80 bender-nginx

Finally, you can use curl to test if the nginx container is working properly.

curl http://127.0.0.1:8080/ 

If you get an answer with "404 Not Found", nginx will work fine. Nginx informs you that the requested page was not found.

Version

Release: 1.5.0

License

BSD

Author Information

Copyright © 2024 Cogline.v3.

About

Installs ansible-bender, a tool which bends containers using Ansible playbooks and turns them into container images.

Install
ansible-galaxy install coglinev3/ansible-role-ansible_bender
GitHub repository
License
bsd-3-clause
Downloads
5314
Owner