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

Configure podman networks #38

Merged

Conversation

laurent-indermuehle
Copy link
Contributor

@laurent-indermuehle laurent-indermuehle commented Jun 14, 2021

This pull request adds Podman network options that allow usage of static IP in containers. And also add Detach mode support.

With the following molecule.yml you can write scenarios that tests communication between containers without relying on complicated DNS setup:

  platforms:
  
    - name: node1
      registry: &redhat {url: registry.access.redhat.com}
      image: &image ubi8/ubi-init
      tmpfs: &tmpfs ['/run', '/tmp']
      volumes: &volumes ['/sys/fs/cgroup:/sys/fs/cgroup:ro']
      capabilities: &capabilities ['SYS_ADMIN', 'NET_ADMIN']
      command: &command "/usr/sbin/init"
      security_opts: &security_opts ['label=disable']
      network: &network setup_dedicated
      subnet: &subnet '10.90.0.0/16'
      etc_hosts: &etc_hosts
        "node1": "10.90.0.101"
        "node2": "10.90.0.102"
      ip: 10.90.0.101
  
    - name: node2
      registry: *redhat
      image: *image
      tmpfs: *tmpfs
      volumes: *volumes
      capabilities: *capabilities
      command: *command
      security_opts: *security_opts
      network: *network
      subnet: *subnet
      etc_hosts: *etc_hosts
      ip: 10.90.0.102

It is impossible to change the /etc/hosts file on a running container. This is why I edited the create.yml Playbook to add this feature.

Copy link
Contributor

@tadeboro tadeboro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Ansible 2.9 is still supported, I think we should add support for this functionality in such a way that does not exclude users of Ansible 2.9.

lib/molecule_podman/playbooks/create.yml Show resolved Hide resolved
failed_when: false

- name: Create podman network dedicated to this scenario
containers.podman.podman_network:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@laurent-indermuehle
Copy link
Contributor Author

I have no idea how to implement this feature without the podman_network module.
I guess I'll leave this PR open until Ansible 2.9 support is dropped :(

@tadeboro
Copy link
Contributor

As far as I can tell, there are two possible ways forward:

  1. We implement this functionality the same way the rest of the driver is implemented - using a command module calling the podman executable.
  2. We inform podman driver users that they need to have the podman collection installed.

Both options are fine with me, but since I am not a maintainer, I cannot tell which one is prefferable.

@ssbarnea
Copy link
Member

IMHO, i am inclined to add code that detects missing collection and require user to install it, eventually even its version.

I doubt we have the ability to maintain two versions of the podman modules, so we can consider that podman driver works only with the latest collection, and not with the embedded (outdated) versions from ansible 2.9.

@ssbarnea ssbarnea changed the title Lie podman networks Configure podman networks Jun 14, 2021
@ssbarnea ssbarnea added the feature This issue/PR relates to a feature request. label Jun 14, 2021
@tadeboro
Copy link
Contributor

I doubt we have the ability to maintain two versions of the podman modules, so we can consider that podman driver works only with the latest collection, and not with the embedded (outdated) versions from ansible 2.9.

To make matters even worse, Ansible 2.9 is actually missing a lot of content from the podman collection. The podman_network stuff being such content that was added after modules moved from ansible/ansible.

In this case, I think this PR is OK, but we should probably add code that makes sure collection is installed before merging this.

@laurent-indermuehle
Copy link
Contributor Author

Do we check the version of the collection containers.podman only if network is set?

@sshnaidm
Copy link
Collaborator

I wonder if it's only module that can use collections. If not - probably we can install collection as a external dependency like we do with any pip module. It's a mess to have it implemented with podman commands when we have a collection.

@sshnaidm
Copy link
Collaborator

Do we check the version of the collection containers.podman only if network is set?

The problem is that in 2.9 there are no any podman collections. (only podman image module)

@tadeboro
Copy link
Contributor

I would keep things simple and always require podman collection. Anisble 2.9 can work well enough with collections that this should not be a problem.

ssbarnea added a commit to ansible/ansible-lint that referenced this pull request Jun 15, 2021
Adds utility method that detects if a collection is installed or if
it outdated and exits. This functionality is not directly used by
the linter yet but putting this code near similar prerun method makes
it easier to reuse in other related projects.

Related: ansible-community/molecule-podman#38
ssbarnea added a commit to ansible/ansible-lint that referenced this pull request Jun 15, 2021
Adds utility method that detects if a collection is installed or if
it outdated and exits. This functionality is not directly used by
the linter yet but putting this code near similar prerun method makes
it easier to reuse in other related projects.

Related: ansible-community/molecule-podman#38
ssbarnea added a commit to ansible/ansible-lint that referenced this pull request Jun 15, 2021
Adds utility method that detects if a collection is installed or if
it outdated and exits. This functionality is not directly used by
the linter yet but putting this code near similar prerun method makes
it easier to reuse in other related projects.

Related: ansible-community/molecule-podman#38
@laurent-indermuehle
Copy link
Contributor Author

@ssbarnea thanks for the utility method require_collection. But how and where should I use it?

ssbarnea added a commit to ansible/ansible-lint that referenced this pull request Jun 16, 2021
Adds utility method that detects if a collection is installed or if
it outdated and exits. This functionality is not directly used by
the linter yet but putting this code near similar prerun method makes
it easier to reuse in other related projects.

Related: ansible-community/molecule-podman#38
@ssbarnea
Copy link
Member

@laurent-indermuehle You don't need to do it yourself, we already merged that. Now your code should run fine and fail nicely if requires collection is missing or outdated.

@ssbarnea ssbarnea merged commit a3147e7 into ansible-community:master Jun 16, 2021
@laurent-indermuehle
Copy link
Contributor Author

@ssbarnea oh I see! Thanks for your work!

Glad I could add some features! Have a nice day.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants