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

fix: simplify podman executable path lookup #142

Merged
merged 6 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
- name: Converge
hosts: all
tasks:
- name: test
- name: Test
ansible.builtin.debug:
msg: it worked!
30 changes: 14 additions & 16 deletions src/molecule_podman/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
vars:
podman_exec: "{{ lookup('env','MOLECULE_PODMAN_EXECUTABLE')|default('podman',true) }}"
tasks:
- name: get podman executable path
ansible.builtin.command: which {{ podman_exec }}
register: podman_path
environment:
PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin"
- name: Get podman executable path # noqa: command-instead-of-shell
ansible.builtin.shell: "command -v {{ podman_exec }}"
register: _podman_path
changed_when: false

- name: save path to executable as fact
- name: Register podman executable path
ansible.builtin.set_fact:
podman_cmd: "{{ podman_path.stdout }}"
podman_cmd: "{{ _podman_path.stdout }}"

- name: Set async_dir for HOME env
ansible.builtin.set_fact:
Expand All @@ -44,7 +42,7 @@

- name: Check presence of custom Dockerfiles
ansible.builtin.stat:
path: "{{ molecule_scenario_directory + '/' + (item.dockerfile | default( 'Dockerfile.j2')) }}"
path: "{{ molecule_scenario_directory + '/' + (item.dockerfile | default('Dockerfile.j2')) }}"
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: "Dockerfile: {{ item.dockerfile | default('None specified') }}"
Expand All @@ -54,9 +52,9 @@
ansible.builtin.template:
src: >-
{%- if dockerfile_stats.results[i].stat.exists -%}
{{ molecule_scenario_directory + '/' + (item.dockerfile | default( 'Dockerfile.j2')) }}
{{ molecule_scenario_directory + '/' + (item.dockerfile | default('Dockerfile.j2')) }}
{%- else -%}
{{ playbook_dir + '/Dockerfile.j2' }}
{{ playbook_dir + '/Dockerfile.j2' }}
{%- endif -%}
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
mode: "0600"
Expand Down Expand Up @@ -85,7 +83,7 @@
{{ podman_cmd }} 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 %}
{% if item.item.buildargs is defined %}{% for i, k in item.item.buildargs.items() %}--build-arg={{ i }}={{ k }}{% endfor %}{% endif %}
{% if item.item.pull is defined %}--pull={{ item.item.pull }}{% endif %}
with_items: "{{ platforms.results }}"
loop_control:
Expand Down Expand Up @@ -164,18 +162,18 @@
{% if item.volumes is defined %}{% for i in item.volumes %}--volume {{ i }} {% endfor %}{% endif %}
{% if item.tmpfs is defined %}{% for i in item.tmpfs %}--tmpfs={{ i }} {% endfor %}{% endif %}
{% if item.capabilities is defined %}{% for i in item.capabilities %}--cap-add={{ i }} {% endfor %}{% endif %}
{% if item.exposed_ports is defined %}--expose="{{ item.exposed_ports|join(',') }}"{% endif %}
{% if item.exposed_ports is defined %}--expose="{{ item.exposed_ports | join(',') }}"{% endif %}
{% if item.published_ports is defined %}{% for i in item.published_ports %}--publish={{ i }} {% endfor %}{% endif %}
{% if item.ulimits is defined %}{% for i in item.ulimits %}--ulimit={{ i }} {% endfor %}{% endif %}
{% if item.dns_servers is defined %}--dns="{{ item.dns_servers|join(',') }}"{% endif %}
{% if item.env is defined %}{% for i,k in item.env.items() %}--env={{ i }}={{ k }} {% endfor %}{% endif %}
{% if item.dns_servers is defined %}--dns="{{ item.dns_servers | join(',') }}"{% endif %}
{% if item.env is defined %}{% for i, k in item.env.items() %}--env={{ i }}={{ k }} {% endfor %}{% endif %}
{% if item.restart_policy is defined %}--restart={{ item.restart_policy }}{% if item.restart_retries is defined %}:{{ item.restart_retries }}{% endif %}{% endif %}
{% if item.tty is defined %}--tty={{ item.tty }}{% endif %}
{% if item.network is defined %}--network={{ item.network }}{% endif %}
{% if item.ip is defined %}--ip={{ item.ip }}{% endif %}
{% if item.etc_hosts is defined %}{% for i,k in item.etc_hosts.items() %}{% if i != item.name %}--add-host {{ i }}:{{ k }} {% endif %}{% endfor %}{% endif %}
{% if item.etc_hosts is defined %}{% for i, k in item.etc_hosts.items() %}{% if i != item.name %}--add-host {{ i }}:{{ k }} {% endif %}{% endfor %}{% endif %}
{% if item.hostname is defined %}--hostname={{ item.hostname }}{% elif item.name is defined %}--hostname={{ item.name }}{% endif %}
{% if item.systemd is defined %}--systemd={{ item.systemd|string|lower }}{% endif %}
{% if item.systemd is defined %}--systemd={{ item.systemd | string | lower }}{% endif %}
{{ item.extra_opts | default([]) | join(' ') }}
{{ item.pre_build_image | default(false) | ternary('', 'molecule_local/') }}{{ item.image }}
{{ (command_directives_dict | default({}))[item.name] | default('') }}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule_podman/playbooks/validate-dockerfile.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ansible-playbook
---
- hosts: localhost
- name: Validate dockerfile
hosts: localhost
connection: local
gather_facts: false
collections:
Expand Down