coglinev3.ansible_container
Ansible Role: 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が必要です。ansible-benderは、私のGalaxyロールcoglinev3.ansible_benderを使用してインストールできます。
ロール変数
利用可能な変数は以下に示します(デフォルト値はdefaults/main.ymlで確認できます):
# sudoを使用するかどうか
ansible_container_become: true
# インストールされたパッケージの状態:absent | present | latest
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.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.