-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TimGrt/dev
Dev
- Loading branch information
Showing
6 changed files
with
110 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# MD013/line-length - Line length | ||
MD013: | ||
# Number of characters, basically allowing very long lines | ||
line_length: 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
name: Check for merge conflict markers | ||
- id: trailing-whitespace | ||
name: Remove trailing whitespaces | ||
args: [--markdown-linebreak-ext=md] | ||
- id: no-commit-to-branch | ||
name: Ensure committing to allowed branch | ||
- repo: https://github.com/igorshubovych/markdownlint-cli | ||
rev: v0.41.0 | ||
hooks: | ||
- id: markdownlint | ||
name: Lint Markdown files | ||
- repo: https://github.com/python-jsonschema/check-jsonschema | ||
rev: 0.28.6 | ||
hooks: | ||
- id: check-github-workflows | ||
name: Check Github workflows | ||
- repo: https://github.com/hadolint/hadolint | ||
rev: v2.12.0 | ||
hooks: | ||
- id: hadolint-docker | ||
name: Lint Dockerfile | ||
entry: ghcr.io/hadolint/hadolint:latest-alpine hadolint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,80 @@ | ||
# RHEL 8 Ansible Test Image | ||
|
||
RHEL 8 Docker container based on UBI 8 for Ansible playbook and role testing. | ||
RHEL 8 Docker container for Ansible playbook and role testing. | ||
This container is used to test Ansible roles and playbooks (e.g. with molecule) running locally inside the container. | ||
A non-priviledged user `ansible` is created with password-less sudo configured. | ||
A user `ansible` is created with password-less sudo configured. | ||
|
||
[![Docker Build and Publish](https://github.com/TimGrt/docker-rhel8-ansible/actions/workflows/ci.yml/badge.svg)](https://github.com/TimGrt/docker-rhel8-ansible/actions/workflows/ci.yml) ![Docker Pulls](https://img.shields.io/docker/pulls/timgrt/rhel8-ansible) ![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/timgrt/docker-rhel8-ansible/main) | ||
|
||
## Tags | ||
|
||
The following tags are available: | ||
|
||
- `latest`: Latest stable version of Ansible on Python 3.8 | ||
## How to Build | ||
|
||
To build the image on your own locally, do the following: | ||
If you need to build the image on your own locally, do the following: | ||
|
||
1. [Install Docker](https://docs.docker.com/engine/installation/). | ||
2. Clone the repository and `cd` into this directory. | ||
3. Run `docker build -t rhel8-ansible .` | ||
1. Install container runtime, I use [Podman](https://podman.io/docs/installation) but you may also use [Docker](https://docs.docker.com/engine/installation/). | ||
2. Clone the repository and `cd` into this directory. | ||
3. Run `podman build -t rhel8-ansible .` | ||
|
||
## How to Use Standalone | ||
|
||
1. [Install Docker](https://docs.docker.com/engine/installation/). | ||
2. Pull this image from Docker Hub or use the image you built earlier, e.g. called `rhel8-ansible:latest` for the next step. | ||
```bash | ||
docker pull timgrt/rhel8-ansible:latest | ||
``` | ||
3. Run a container from the image. To test my Ansible roles, I add in a volume mounted from the current working directory with ``--volume=`pwd`:/etc/ansible/roles/role_under_test:ro``. | ||
```bash | ||
docker run --detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro timgrt/rhel8-ansible:latest | ||
``` | ||
4. Use Ansible inside the container. | ||
```bash | ||
docker exec --tty [container_id] env TERM=xterm ansible --version | ||
``` | ||
```bash | ||
docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml | ||
``` | ||
1. Install container runtime, I use [Podman](https://podman.io/docs/installation). You may also use [Docker](https://docs.docker.com/engine/installation/), but you'll have to adjust some configurations. | ||
2. Pull this image from Docker Hub or use the image you built earlier, e.g. called `rhel8-ansible:latest` for the next step. | ||
|
||
```bash | ||
podman pull timgrt/rhel8-ansible:latest | ||
``` | ||
|
||
3. Run a container from the image. | ||
|
||
```console | ||
podman run --detach --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro --name instance timgrt/rhel8-ansible:latest | ||
``` | ||
|
||
4. Use the container in your inventory with the *podman* connection plugin. | ||
|
||
```ini | ||
[test] | ||
instance ansible_connection=podman ansible_user=ansible | ||
``` | ||
|
||
Using the `ansible` user inside the container to be able to test with become. | ||
|
||
You'll need to have the Ansible collection `containers.podman` installed. | ||
|
||
```console | ||
ansible-galaxy collection install containers.podman | ||
``` | ||
|
||
## How to Use with Molecule | ||
|
||
1. [Install Docker](https://docs.docker.com/engine/installation/). | ||
2. [Install Molecule](https://molecule.readthedocs.io/en/latest/installation.html). | ||
3. Add Image in molecule.yml. | ||
|
||
For example: | ||
```yaml | ||
--- | ||
driver: | ||
name: docker | ||
platforms: | ||
- name: rhel8 | ||
image: timgrt/rhel8-ansible:latest | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
privileged: true | ||
command: "/usr/sbin/init" | ||
pre_build_image: true | ||
provisioner: | ||
name: ansible | ||
config_options: | ||
defaults: | ||
interpreter_python: auto_silent | ||
callback_whitelist: profile_tasks, timer, yaml | ||
stdout_callback: yaml | ||
ssh_connection: | ||
pipelining: false | ||
inventory: | ||
host_vars: | ||
rhel8: | ||
ansible_user: ansible | ||
``` | ||
1. [Install Docker](https://docs.docker.com/engine/installation/). | ||
2. [Install Molecule](https://ansible.readthedocs.io/projects/molecule/installation/). | ||
3. Add Image in `molecule.yml`. | ||
|
||
```yaml | ||
--- | ||
driver: | ||
name: podman | ||
platforms: | ||
- name: rhel8 | ||
image: docker.io/timgrt/rhel8-ansible:latest | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
command: "/usr/sbin/init" | ||
pre_build_image: true | ||
provisioner: | ||
name: ansible | ||
config_options: | ||
defaults: | ||
interpreter_python: auto_silent | ||
callback_result_format: yaml | ||
ssh_connection: | ||
pipelining: false | ||
inventory: | ||
host_vars: | ||
rhel8: | ||
ansible_user: ansible | ||
``` | ||
|
||
## Author | ||
|
||
Created 2021 by Tim Grützmacher | ||
Created 2022 by Tim Grützmacher, inspired by [Jeff Geerling](https://www.jeffgeerling.com/) |