Code Monkey home page Code Monkey logo

Comments (10)

Luap99 avatar Luap99 commented on May 24, 2024 6

I have added the --format json option in containers/podman#7329. This will be included in podman v2.1.

$ podman generate systemd --format json ad352b0cb348
{
 "container-ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667": "# container-ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667.service\n# autogenerated by Podman 2.1.0-dev\n# Mon Sep 14 20:26:09 CEST 2020\n\n[Unit]\nDescription=Podman container-ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667.service\nDocumentation=man:podman-generate-systemd(1)\nWants=network.target\nAfter=network-online.target\n\n[Service]\nEnvironment=PODMAN_SYSTEMD_UNIT=%n\nRestart=on-failure\nExecStart=/home/paul/go/src/github.com/containers/libpod/bin/podman start ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667\nExecStop=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667\nExecStopPost=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667\nPIDFile=/run/user/1000/containers/overlay-containers/ad352b0cb348cd28d097dae8902a444e5fca1aacd834698018aa482437b8f667/userdata/conmon.pid\nKillMode=none\nType=forking\n\n[Install]\nWantedBy=multi-user.target default.target\n"
}

Output for a pod:

$ bin/podman generate systemd --format json pod
{
 "container-6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268": "# container-6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268.service\n# autogenerated by Podman 2.1.0-dev\n# Mon Sep 14 20:37:28 CEST 2020\n\n[Unit]\nDescription=Podman container-6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268.service\nDocumentation=man:podman-generate-systemd(1)\nWants=network.target\nAfter=network-online.target\nBindsTo=pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f.service\nAfter=pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f.service\n\n[Service]\nEnvironment=PODMAN_SYSTEMD_UNIT=%n\nRestart=on-failure\nExecStart=/home/paul/go/src/github.com/containers/libpod/bin/podman start 6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268\nExecStop=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268\nExecStopPost=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268\nPIDFile=/run/user/1000/containers/overlay-containers/6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268/userdata/conmon.pid\nKillMode=none\nType=forking\n\n[Install]\nWantedBy=multi-user.target default.target\n",
 "container-a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a": "# container-a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a.service\n# autogenerated by Podman 2.1.0-dev\n# Mon Sep 14 20:37:28 CEST 2020\n\n[Unit]\nDescription=Podman container-a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a.service\nDocumentation=man:podman-generate-systemd(1)\nWants=network.target\nAfter=network-online.target\nBindsTo=pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f.service\nAfter=pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f.service\n\n[Service]\nEnvironment=PODMAN_SYSTEMD_UNIT=%n\nRestart=on-failure\nExecStart=/home/paul/go/src/github.com/containers/libpod/bin/podman start a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a\nExecStop=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a\nExecStopPost=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a\nPIDFile=/run/user/1000/containers/overlay-containers/a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a/userdata/conmon.pid\nKillMode=none\nType=forking\n\n[Install]\nWantedBy=multi-user.target default.target\n",
 "pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f": "# pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f.service\n# autogenerated by Podman 2.1.0-dev\n# Mon Sep 14 20:37:28 CEST 2020\n\n[Unit]\nDescription=Podman pod-9c478a337035daffc68d0a0618bfce0ec97ff9612a3face59302ad51b539101f.service\nDocumentation=man:podman-generate-systemd(1)\nWants=network.target\nAfter=network-online.target\nRequires=container-6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268.service container-a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a.service\nBefore=container-6ae41af23d0292450901204a29227e0420c081a1a71b89429142d5aa719a5268.service container-a3aeb4ccd27b3b66a5786982da65da9ee59a9c1da1e70951ce99b53a0542361a.service\n\n[Service]\nEnvironment=PODMAN_SYSTEMD_UNIT=%n\nRestart=on-failure\nExecStart=/home/paul/go/src/github.com/containers/libpod/bin/podman start 7443127611f85a0f2fbe7a5a33d94b262717e040295a1c33134775b991240b30\nExecStop=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 7443127611f85a0f2fbe7a5a33d94b262717e040295a1c33134775b991240b30\nExecStopPost=/home/paul/go/src/github.com/containers/libpod/bin/podman stop -t 10 7443127611f85a0f2fbe7a5a33d94b262717e040295a1c33134775b991240b30\nPIDFile=/run/user/1000/containers/overlay-containers/7443127611f85a0f2fbe7a5a33d94b262717e040295a1c33134775b991240b30/userdata/conmon.pid\nKillMode=none\nType=forking\n\n[Install]\nWantedBy=multi-user.target default.target\n"
}

from ansible-podman-collections.

sshnaidm avatar sshnaidm commented on May 24, 2024 2

This is an open source project, you're welcome to send a patch.

from ansible-podman-collections.

soulmanos avatar soulmanos commented on May 24, 2024 1

I'd be keen for this functionality too, likewise using shell

from ansible-podman-collections.

sshnaidm avatar sshnaidm commented on May 24, 2024

@Klaas- , I think we'd better to make it as a separate module. Even if we integrate it into podman_container, it's always good to have it separately in case you need just to generate files for existing containers.
You can just parse output of command, it's actually the text of systemd file, like we do here with version for example: https://github.com/containers/ansible-podman-collections/blob/master/plugins/modules/podman_container.py#L1777-L1778

def _get_podman_version(self):
      # pylint: disable=unused-variable
      rc, out, err = self.module.run_command(
          [self.module.params['executable'], b'--version'])
      if rc != 0 or not out or "version" not in out:
          self.module.fail_json(msg="%s run failed!" % self.module.params['executable'])
      return out.split("version")[1].strip()

from ansible-podman-collections.

Klaas- avatar Klaas- commented on May 24, 2024

@sshnaidm using the stdout output works for a single container, my main focus for now is getting awx to work (and that is a pod with multiple containers). I looked at the output, that's a concatination of the multiple service files without a real seperator if I did not misread the output :) I was going to suggest to add a json output or something like that but go is not really my language :D

from ansible-podman-collections.

sshnaidm avatar sshnaidm commented on May 24, 2024

@Klaas- you're right, there is no visible delimiter. We can try to rely on comments, which are first lines in the file like:

# pod-mypod.service
# autogenerated by Podman 1.8.1
# Wed Apr  8 22:16:40 IDT 2020

But it'll be a guess.
Can you point me please to pod configuration with AWX?
I'm not sure Podman team will adopt JSON for a file output, might be challenging with multiline and indentation. But for a visible and well defined delimiter I think would be reasonable to ask.

from ansible-podman-collections.

Klaas- avatar Klaas- commented on May 24, 2024

@sshnaidm I'm currently working on getting the current version to work ikke-t/awx_pod#7 is what I'm using for now, but I want to replace the podman role with something working smoother :)

from ansible-podman-collections.

sshnaidm avatar sshnaidm commented on May 24, 2024

@Klaas- hi, any work in progress about generation of systemd files?
I think to start systemd files generation for pods and containers, also play_kube functionality. I wonder if you made something or maybe have use cases for this. I think it's worth to add automatic generation of systemd units and their installation.

from ansible-podman-collections.

Klaas- avatar Klaas- commented on May 24, 2024

@sshnaidm hi, no I haven't worked on it more. For now I my primary usecase is the awx_pod and that is using https://github.com/ikke-t/podman-container-systemd - I would like to see this implemented here but I haven't found the time yet :D

from ansible-podman-collections.

dan-m8t avatar dan-m8t commented on May 24, 2024

any updates here? Right now I'm using the shell module to create systemd files.

from ansible-podman-collections.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.