Last active
February 22, 2020 11:12
-
-
Save gdamjan/771b826afedcda30c876d30ce60b3bc5 to your computer and use it in GitHub Desktop.
ansible + podman & buildah
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
--- | |
# seems to not work currently (buildah 1.14.0 - Permission denied when writing to /root/ of the container) | |
# ansible-playbook buildah.yml | |
# | |
# `debian:buster` and `image-name` should probably be extra vars | |
# | |
- name: bootstrap a container | |
hosts: localhost | |
become: no | |
gather_facts: no | |
tasks: | |
- name: bootstrap container - create a new container | |
command: buildah from --name container debian:buster | |
- name: bootstrap container - apt update | |
command: buildah run --network host container apt update | |
- name: bootstrap container - apt install python | |
command: buildah run --network host container apt install -y python | |
- name: add container to host group | |
add_host: | |
hostname: container | |
ansible_connection: buildah | |
- name: provision container | |
hosts: container | |
tasks: | |
- ping: | |
- name: wind down container | |
hosts: localhost | |
become: no | |
gather_facts: no | |
tasks: | |
- name: commit container | |
command: buildah commit container image-name | |
- name: remove container | |
command: buildah rm container |
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
--- | |
# works with ansible >=2.9 and podman 1.8.0 | |
# ansible-playbook podman.yml | |
# | |
# `debian:buster` and `image-name` should probably be extra vars | |
# | |
- name: bootstrap a container | |
hosts: localhost | |
become: no | |
gather_facts: no | |
tasks: | |
- name: bootstrap container - create a new container | |
command: podman run -d --name container debian:buster sleep infinity | |
- name: bootstrap container - apt update | |
command: podman exec container apt update | |
- name: bootstrap container - apt install python | |
command: podman exec container apt install -y python | |
- name: add container to host group | |
add_host: | |
hostname: container | |
ansible_connection: podman | |
- name: provision container | |
hosts: container | |
tasks: | |
- ping: | |
- name: wind down container | |
hosts: localhost | |
become: no | |
gather_facts: no | |
tasks: | |
- name: stop container | |
command: podman stop container | |
- name: commit container | |
command: podman commit container image-name | |
- name: remove container | |
command: podman rm container |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment