mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Add support for network-alias flag (#314)
* Add support for network-alias flag * Ignore idempotency assert in tests Co-authored-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
parent
b6c20717ae
commit
15cd7623af
6 changed files with 72 additions and 1 deletions
|
|
@ -92,6 +92,7 @@ ARGUMENTS_SPEC_CONTAINER = dict(
|
|||
memory_swappiness=dict(type='int'),
|
||||
mount=dict(type='str'),
|
||||
network=dict(type='list', elements='str', aliases=['net', 'network_mode']),
|
||||
network_aliases=dict(type='list', elements='str'),
|
||||
no_hosts=dict(type='bool'),
|
||||
oom_kill_disable=dict(type='bool'),
|
||||
oom_score_adj=dict(type='int'),
|
||||
|
|
@ -475,6 +476,11 @@ class PodmanModuleParams:
|
|||
def addparam_network(self, c):
|
||||
return c + ['--network', ",".join(self.params['network'])]
|
||||
|
||||
def addparam_network_aliases(self, c):
|
||||
for alias in self.params['network_aliases']:
|
||||
c += ['--network-alias', alias]
|
||||
return c
|
||||
|
||||
def addparam_no_hosts(self, c):
|
||||
return c + ['--no-hosts=%s' % self.params['no_hosts']]
|
||||
|
||||
|
|
|
|||
|
|
@ -563,6 +563,13 @@ options:
|
|||
aliases:
|
||||
- net
|
||||
- network_mode
|
||||
network_aliases:
|
||||
description:
|
||||
- Add network-scoped alias for the container.
|
||||
A container will only have access to aliases on the first network that it joins.
|
||||
This is a limitation that will be removed in a later release.
|
||||
type: list
|
||||
elements: str
|
||||
no_hosts:
|
||||
description:
|
||||
- Do not create /etc/hosts for the container
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
- name: Remove container netcontainer
|
||||
containers.podman.podman_container:
|
||||
name: netcontainer
|
||||
state: absent
|
||||
|
||||
- name: Run container with testnet and two aliases
|
||||
containers.podman.podman_container:
|
||||
name: netcontainer
|
||||
image: "{{ idem_image }}"
|
||||
command: 1h
|
||||
state: started
|
||||
network: testnet
|
||||
network_aliases:
|
||||
- netcontainer-alias-a
|
||||
- netcontainer-alias-b
|
||||
|
||||
- name: Run container again with testnet and same two aliases
|
||||
containers.podman.podman_container:
|
||||
name: netcontainer
|
||||
image: "{{ idem_image }}"
|
||||
command: 1h
|
||||
state: present
|
||||
network: testnet
|
||||
network_aliases:
|
||||
- netcontainer-alias-a
|
||||
- netcontainer-alias-b
|
||||
register: info
|
||||
|
||||
- name: Check info for 2 runs of testnet
|
||||
assert:
|
||||
that:
|
||||
- info is not changed
|
||||
|
||||
- name: Run changed container with testnet and three aliases
|
||||
containers.podman.podman_container:
|
||||
name: netcontainer
|
||||
image: "{{ idem_image }}"
|
||||
command: 1h
|
||||
state: present
|
||||
network: testnet
|
||||
network_aliases:
|
||||
- netcontainer-alias-a
|
||||
- netcontainer-alias-b
|
||||
- netcontainer-alias-c
|
||||
register: info1
|
||||
|
||||
- name: Check info
|
||||
assert:
|
||||
that:
|
||||
- info1 is changed
|
||||
ignore_errors: true
|
||||
|
|
@ -42,5 +42,5 @@
|
|||
apply:
|
||||
become: true
|
||||
|
||||
- name: Test idempotency for root network containers
|
||||
- name: Test idempotency for rootless network containers
|
||||
include_tasks: rootless-podman-network.yml
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@
|
|||
- include_tasks: idem_networks.yml
|
||||
loop: "{{ testdata }}"
|
||||
|
||||
- include_tasks: idem_network_aliases.yml
|
||||
|
||||
always:
|
||||
|
||||
- name: Delete all pods leftovers from tests
|
||||
|
|
|
|||
|
|
@ -191,3 +191,8 @@
|
|||
assert:
|
||||
that:
|
||||
- info9 is not changed
|
||||
|
||||
- name: Make sure container doesn't exist
|
||||
containers.podman.podman_container:
|
||||
name: root-idempotency
|
||||
state: absent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue