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

Commit

Permalink
Configure podman networks (#38)
Browse files Browse the repository at this point in the history
* Add create podman network

This feature allow to use static IP in scenarios

* Add filter to IP of current node to prevent duplication in etc_hosts

* Fix published_ports by repeating the option instead of passing a list

* Add support for podman --detach option

* Add support for podman --ip option

* Reformat typo

The real purpose of this commit it to try to unlock the checks in
the github PR:
#33
  • Loading branch information
laurent-indermuehle authored Jun 16, 2021
1 parent 38b16b8 commit a3147e7
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions lib/molecule_podman/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@
loop_control:
label: "{{ item.name }}"

- name: Discover local podman networks
containers.podman.podman_network_info:
name: "{{ item.network }}"
loop: "{{ molecule_yml.platforms | flatten(levels=1) }}"
loop_control:
extended: true
label: "{{ item.name }}: {{ item.network | default('None specified') }}"
register: podman_network
when:
- item.network is defined
- ansible_loop.first
failed_when: false

- name: Create podman network dedicated to this scenario
containers.podman.podman_network:
name: "{{ podman_network.results[0].ansible_loop.allitems[0].network }}"
subnet:
"{{ podman_network.results[0].ansible_loop.allitems[0].subnet }}"
when:
- podman_network.results[0].msg is defined
- "'no such network' in podman_network.results[0].msg"
- podman_network.results[0].networks is undefined

- name: Create molecule instance(s)
command: >
podman
Expand All @@ -112,19 +135,21 @@
--name "{{ item.name }}"
{% if item.pid_mode is defined %}--pid={{ item.pid_mode }}{% endif %}
{% if item.privileged is defined %}--privileged={{ item.privileged }}{% endif %}
{% if item.detach is defined %}--detach{% endif %}
{% if item.security_opts is defined %}{% for i in item.security_opts %}--security-opt {{ i }} {% endfor %}{% endif %}
{% 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.published_ports is defined %}--publish="{{ item.published_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.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.etc_hosts is defined %}{% for i,k in item.etc_hosts.items() %}--add-host {{ i }}:{{ k }} {% endfor %}{% 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.hostname is defined %}--hostname={{ item.hostname }}{% elif item.name is defined %}--hostname={{ item.name }}{% endif %}
{% if item.systemd is defined %}--systemd={{ item.systemd }}{% endif %}
{{ item.pre_build_image | default(false) | ternary('', 'molecule_local/') }}{{ item.image }}
Expand All @@ -144,4 +169,4 @@
retries: 300
with_items: "{{ server.results }}"
loop_control:
label: "{{ item.item.name | default('Unamed')}}"
label: "{{ item.item.name | default('Unnamed')}}"

0 comments on commit a3147e7

Please sign in to comment.