-
Notifications
You must be signed in to change notification settings - Fork 21
Add ability to deploy into a container like vms #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ehelms
wants to merge
1
commit into
theforeman:master
Choose a base branch
from
ehelms:add-container-provider
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,118 @@ | ||
| --- | ||
| - name: Create a container to deploy and test in | ||
| gather_facts: false | ||
| hosts: | ||
| - localhost | ||
| vars: | ||
| container: quadlet | ||
| tasks: | ||
| - name: Start containers | ||
| when: container_action == 'start' | ||
| block: | ||
| - name: Start CentOS 9 Stream container | ||
| containers.podman.podman_container: | ||
| name: "{{ container }}" | ||
| image: quay.io/centos/centos:stream9 | ||
| state: started | ||
| force_restart: true | ||
| privileged: true | ||
| hostname: "{{ container }}.example.com" | ||
| restart_policy: "always" | ||
| ports: | ||
| - "22" | ||
| - "8080:80" | ||
| - "8443:443" | ||
| command: sleep infinity | ||
|
|
||
| - name: Wait for container to be ready | ||
| ansible.builtin.wait_for: | ||
| timeout: 10 | ||
|
|
||
| - name: Install systemd and SSH in container | ||
| containers.podman.podman_container_exec: | ||
| name: "{{ container }}" | ||
| command: "{{ item }}" | ||
| loop: | ||
| - "dnf install -y systemd openssh-server passwd python3 podman" | ||
| - "echo 'root:password' | chpasswd" | ||
| - "sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config" | ||
| changed_when: false | ||
|
|
||
| - name: Commit container with systemd installed | ||
| ansible.builtin.command: | ||
| cmd: "podman commit {{ container }} {{ container }}-systemd" | ||
| changed_when: false | ||
|
|
||
| - name: Stop container to restart with systemd | ||
| containers.podman.podman_container: | ||
| name: "{{ container }}" | ||
| state: stopped | ||
|
|
||
| - name: Remove container completely | ||
| containers.podman.podman_container: | ||
| name: "{{ container }}" | ||
| state: absent | ||
|
|
||
| - name: Start new container with systemd as PID 1 | ||
| containers.podman.podman_container: | ||
| name: "{{ container }}" | ||
| image: "{{ container }}-systemd" | ||
| state: started | ||
| privileged: true | ||
| hostname: "{{ container }}.example.com" | ||
| restart_policy: "always" | ||
| ports: | ||
| - "22" | ||
| - "8080:80" | ||
| - "8443:443" | ||
| command: /usr/sbin/init | ||
|
|
||
| - name: Wait for systemd to initialize | ||
| ansible.builtin.wait_for: | ||
| timeout: 15 | ||
|
|
||
| - name: Create local_containers inventory | ||
| ansible.builtin.copy: | ||
| dest: "{{ inventory_dir }}/local_containers" | ||
| content: | | ||
| all: | ||
| hosts: | ||
| {{ container }}: | ||
| ansible_connection: podman | ||
| ansible_user: root | ||
| mode: "0664" | ||
|
|
||
| - name: Stop containers | ||
| when: container_action == 'stop' | ||
| block: | ||
| - name: Stop and remove container | ||
| containers.podman.podman_container: | ||
| name: "{{ container }}" | ||
| state: absent | ||
|
|
||
| - name: Remove containers inventory | ||
| ansible.builtin.file: | ||
| state: absent | ||
| path: "{{ inventory_dir }}/local_containers" | ||
|
|
||
| - name: Show container status | ||
| when: container_action == 'status' | ||
| block: | ||
| - name: Get container status | ||
| containers.podman.podman_container_info: | ||
| name: "{{ container }}" | ||
| register: container_info | ||
| ignore_errors: true | ||
|
|
||
| - name: Display container status | ||
| ansible.builtin.debug: | ||
| msg: | | ||
| Container Status: | ||
| {% if container_info.containers | length > 0 %} | ||
| Name: {{ container_info.containers[0].Name }} | ||
| State: {{ container_info.containers[0].State.Status }} | ||
| Image: {{ container_info.containers[0].Config.Image }} | ||
| Created: {{ container_info.containers[0].Created }} | ||
| {% else %} | ||
| Container "{{ container }}" not found or not running | ||
| {% endif %} | ||
This file contains hidden or 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,15 @@ | ||
| --- | ||
| help: | | ||
| Manage development and testing containers. | ||
|
|
||
| variables: | ||
| container_action: | ||
| parameter: container_action | ||
| help: Start the containers | ||
| choices: | ||
| - start | ||
| - stop | ||
| - status | ||
| containers: | ||
| help: Which containers to manage, defaults to quadlet. | ||
| action: store |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there systemd-enabled centos images available somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find one.