Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Allow podman executable override with env #53

Merged
merged 21 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ This plugin requires `containers.podman` collection to be present:

Please note that this driver is currently in its early stage of development.

**Change podman executable**
NikolineLykPedersen marked this conversation as resolved.
Show resolved Hide resolved

To change the podman executable from the standard podman, export environment variable MOLECULE_PODMAN_EXECUTABLE. For instance if you wish to run molecule with podman-remote instead of ordinary podman, the variable can be exportet as:
NikolineLykPedersen marked this conversation as resolved.
Show resolved Hide resolved

export MOLECULE_PODMAN_EXECUTABLE=podman-remote
NikolineLykPedersen marked this conversation as resolved.
Show resolved Hide resolved

.. _get-involved:

Get Involved
Expand Down
8 changes: 6 additions & 2 deletions src/molecule_podman/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
from molecule.util import lru_cache

log = logger.get_logger(__name__)
# To change the podman executable, set environment variable
# MOLECULE_PODMAN_EXECUTABLE
# An example could be MOLECULE_PODMAN_EXECUTABLE=podman-remote
podman_exec = os.environ.get("MOLECULE_PODMAN_EXECUTABLE", "podman")
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved


class Podman(Driver):
Expand Down Expand Up @@ -164,7 +168,7 @@ def name(self, value):
@property
def login_cmd_template(self):
return (
"podman exec "
f"{podman_exec} exec "
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
"-e COLUMNS={columns} "
"-e LINES={lines} "
"-e TERM=bash "
Expand All @@ -184,7 +188,7 @@ def login_options(self, instance_name):
return {"instance": instance_name}

def ansible_connection_options(self, instance_name):
return {"ansible_connection": "podman"}
return {"ansible_connection": "podman", "ansible_podman_executable": f"{podman_exec}"}
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved

@lru_cache()
def sanity_checks(self):
Expand Down
13 changes: 9 additions & 4 deletions src/molecule_podman/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
gather_facts: false
no_log: "{{ molecule_no_log }}"
become: "{{ not (item.rootless|default(true)) }}"
vars:
podman_exec: "{{ lookup('env','MOLECULE_PODMAN_EXECUTABLE')|default('podman',true) }}"
tasks:
- name: Log into a container registry
command: >
podman login
{{ podman_exec }} login
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
--username {{ item.registry.credentials.username }}
--password {{ item.registry.credentials.password }}
--tls-verify={{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}
Expand Down Expand Up @@ -54,6 +56,7 @@
- name: Discover local Podman images
containers.podman.podman_image_info:
name: "molecule_local/{{ item.item.name }}"
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
executable: "{{ podman_exec }}"
with_items: "{{ platforms.results }}"
loop_control:
label: "{{ item.item.name | default('None specified') }}"
Expand All @@ -63,7 +66,7 @@

- name: Build an Ansible compatible image # noqa: no-handler
command: >
podman build
{{ podman_exec }} build
-f {{ item.dest }}
-t molecule_local/{{ item.item.image }}
{% if item.item.buildargs is defined %}{% for i,k in item.item.buildargs.items() %}--build-arg={{ i }}={{ k }} {% endfor %}{% endif %}
Expand Down Expand Up @@ -96,14 +99,15 @@
# https://github.com/ansible-community/molecule-podman/issues/22
- name: Remove possible pre-existing containers
command: >
podman rm -f -i -v {% for key in molecule_yml.platforms %}{{ key.name }} {% endfor %}
{{ podman_exec }} rm -f -i -v {% for key in molecule_yml.platforms %}{{ key.name }} {% endfor %}
register: result
changed_when: true
failed_when: false

- name: Discover local podman networks
containers.podman.podman_network_info:
name: "{{ item.network }}"
executable: "{{ podman_exec }}"
loop: "{{ molecule_yml.platforms | flatten(levels=1) }}"
loop_control:
extended: true
Expand All @@ -117,6 +121,7 @@
- name: Create podman network dedicated to this scenario
containers.podman.podman_network:
name: "{{ podman_network.results[0].ansible_loop.allitems[0].network }}"
executable: "{{ podman_exec }}"
subnet:
"{{ podman_network.results[0].ansible_loop.allitems[0].subnet }}"
when:
Expand All @@ -126,7 +131,7 @@

- name: Create molecule instance(s)
command: >
podman
{{ podman_exec }}
{% if item.cgroup_manager is defined %}--cgroup-manager={{ item.cgroup_manager }}{% endif %}
{% if item.storage_opt is defined %}--storage-opt={{ item.storage_opt }}{% endif %}
{% if item.storage_driver is defined %}--storage-driver={{ item.storage_driver }}{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion src/molecule_podman/playbooks/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
gather_facts: false
no_log: "{{ molecule_no_log }}"
become: "{{ not (item.rootless|default(true)) }}"
vars:
podman_exec: "{{ lookup('env','MOLECULE_PODMAN_EXECUTABLE')|default('podman',true) }}"
tasks:
- name: Destroy molecule instance(s)
shell: podman container exists {{ item.name }} && podman rm -f {{ item.name }} || true
shell: "{{ podman_exec }} container exists {{ item.name }} && {{ podman_exec }} rm -f {{ item.name }} || true"
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
Expand Down