Giter VIP home page Giter VIP logo

ansible-docker-systemd-service's People

Contributors

a0s avatar aderixon avatar andygrunwald avatar brouberol avatar caiges avatar danielmschmidt avatar enigmacurry avatar epou avatar felixb avatar gaell avatar jovandeginste avatar mhutter avatar renovate[bot] avatar silvio avatar talset avatar teddyphreak avatar varac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-docker-systemd-service's Issues

Ansible Galaxy Import failed

Starting import: task_id=2084247621079170876822522174674628311, pulp_id=01916957-70ec-7593-82bb-bf3530cceed7 
 
==== PARAMETERS ==== 
importer username: mhutter 
matched user: mhutter id:4464 
github_user: mhutter 
github_repo: ansible-docker-systemd-service 
github_reference: master 
alternate_clone_url: None 
alternate_namespace_name: None 
alternate_role_name: None 
 
==== CHECK FOR MATCHING ROLE(S) ==== 
user:mhutter repo:ansible-docker-systemd-service matched existing role mhutter.docker-systemd-service id:19056 
 
===== CLONING REPO ===== 
cloning https://github.com/mhutter/ansible-docker-systemd-service ... 
 
===== GIT ATTRIBUTES ===== 
github_reference(branch): master 
github_commit: 41d7736531eb0b4912b72b6cdd97c93c07b99656 
github_commit_message: chore(master): release 2.10.1 (#71)  
github_commit_date: 2024-08-19T08:30:46+02:00 
 
===== LOADING ROLE ===== 
Importing with galaxy-importer 0.4.20 
 
Role loading failed! unknown field in galaxy_info: LegacyGalaxyInfo.__init__() got an unexpected keyword argument 'name' 
 
Traceback (most recent call last):
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/schema.py", line 532, in parse
    galaxy_info = LegacyGalaxyInfo(**metadata["galaxy_info"])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: LegacyGalaxyInfo.__init__() got an unexpected keyword argument 'name'

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/app/galaxy_ng/app/api/v1/tasks.py", line 427, in legacy_role_import
    result = import_legacy_role(checkout_path, namespace.name, importer_config, logger)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/legacy_role.py", line 51, in import_legacy_role
    return _import_legacy_role(dirname, namespace, cfg, logger)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/legacy_role.py", line 57, in _import_legacy_role
    data = LegacyRoleLoader(dirname, namespace, cfg, logger).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/loaders/legacy_role.py", line 41, in load
    self.metadata = self._load_metadata()
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/loaders/legacy_role.py", line 77, in _load_metadata
    return schema.LegacyMetadata.parse(meta_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/schema.py", line 534, in parse
    raise exc.LegacyRoleSchemaError(f"unknown field in galaxy_info: {e}") from e

galaxy_importer.exceptions.LegacyRoleSchemaError: unknown field in galaxy_info: LegacyGalaxyInfo.__init__() got an unexpected keyword argument 'name'  

Failed

Add support for a flexible `container_args` to avoid implementing every `docker run` command line argument

Context

This Ansible module uses its own parameters to support various docker run command line arguments.
Out of those, multiple types are used:

  • Single strings
  • Lists

Examples for single strings:

  • container_network maps to --network
  • container_user maps to --user
  • container_hostname maps to --hostname

Examples for lists:

  • container_volumes maps to --volume
  • container_ports maps to --publish
  • container_hosts maps to --add-host

This is great and marks explicitly how to use this module.
The big downside on this: You need to add additional support for each docker run command line argument into this module. And the docker run reference is looooong.

One proposal would be to make this Ansible more flexible and avoid the burden of implementing every single docker run command line argument by offering ways to add arbitrarily

  • key -> value pairs (for single string values that are only allowed once in a docker run cmd, like --user)
  • key -> list[value] pairs (for docker run cmd arguments that are allowed multiple times like --volume)

How a possible Ansible usage can look like in the future / Usage of the module:

- name: Start image
  include_role:
    name: mhutter.docker-systemd-service
  vars:
    container_name: "hello-world"
    container_image: "hello:v1"
    container_docker_pull_force_source: false

    container_single_args:
      network: my-network
      user: nonroot
      hostname: world
      [...]

    container_multi_args:
      publish:
        - '127.0.0.1:3030:3000'
        - '127.0.0.1:1234:5678'
      volume:
        - '/opt/foo:/var/lib/bar:rw'
      [...]

    [...]

The top-level keys under container_single_args and container_multi_args are not validated They can be defined to whatever you want.

A few keys, like container_image might be good to keep separate, primarily when those are used in a different context (e.g., to craft the systems unit name).

The same can be done for boolean flags via a list like container_boolean_args for keys like --rm or --tty:

container_boolean_args:
  - 'rm'
  - 'tty'

Open decisions

  • Define which keys need to stay separate and used in different contexts
  • Align on a naming for single arguments, boolean arguments, multi list arguments
  • Align on how to do it (strict breaking change + removing the keys or "smooth" migration via deprecating
  • Implementation: Align on several small pull requests or one big one (to keep the default branch working)

Additional notes

  • This would indicate a breaking change to the module and a v1.x might be needed for a release
  • It might be good to deprecate or directly remove the previous parameters that are replaced by the new capability. Removing directly would free up the code base directly.
  • Changelog + Migration guide would be required

Release to galaxy

Latest release on galaxy is 2.0. There are tags fo 2.1.0 and 2.2.0 on github.
Would you mind releasing these versions to galaxy as well?

Update to latest version in ansible galaxy

Hi,

i'm getting the error {"changed": false, "msg": "state is present but all of the following are missing: source"} and i'm assume, thats fixed in the 2.4.0 release, but ansible galaxy lists only 2.2.0

Add option to support updating image on start/restart

Basically I'm proposing to add a flag that changes the unit file to contain

TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill image
ExecStartPre=-/usr/bin/docker rm image
ExecStartPre=/usr/bin/docker pull user/image

as opposed to the current

ExecStartPre=-{{ docker_path }} rm -f {{ container_name }}

I'm going to implement this for my own use, so let me know if you'd like me to submit a pull request.

handler not found when using include_role

Hello, I have found there is an open issue against ansible for handlers not working when using include_role - See ansible/ansible#20493
It was documented as a Note in the documentation until it is addressed: ansible/ansible#72744

In my case I am getting the following error that the handler does not exist

TASK [mhutter.docker-systemd-service : Create unit myapp-instance1_container.service] ****************************************************************************************************************************************************************************
ERROR! The requested handler 'restart container myapp-instance1' was not found in either the main handlers list nor in the listening handlers list

Has anyone else faced this problem?

templates/unit.j2: issue with jinja trim whith endif

Recently templates/unit.j2 has been updated with if condition around container_cmd

{{ container_image }} {% if container_cmd is string %}{{ container_cmd | trim }}{% else %}{{ container_cmd | join(' ') | trim }}{% endif %}

It seems jinja trim line ending by "if" condition and we end up with systems config like

ExecStart=/usr/bin/docker run \
  --name vault \
  --rm \
  --env-file /etc/default/vault \
  --volume /opt/cycloid/vault/config:/vault/config --volume /opt/cycloid/vault/file:/vault/file \
  --publish 8200:8200 \
   \
  \
  \
  \
  \
  \
  --cap-add IPC_LOCK \
  vault:1.5.4 vault server -config /vault/config/local.jsonExecStop=/usr/bin/docker stop vault
ExecStartPost=-/opt/cycloid/vault/unseal.sh

As you can see the newline before ExecStop is not respected.
Should we force a new line before ExecStop ?

Version
ansible 2.9.27
jinja2 2.10-2

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

ansible-galaxy
requirements.yml
  • community.docker 3.12.1
github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/release.yml
  • googleapis/release-please-action v4

  • Check this box to trigger a request for Renovate to run again on this repository

Permissions to env file are not given to the running user if it's not root

If the ansible_ssh_user is different from root (but still a sudoer), the created systemd service fails to start with this error
docker: open /etc/default/<container name>: permission denied.

My current workaround is to change permissions right after the included mhutter.docker-systemd-service role

    - name: Fix https://github.com/mhutter/ansible-docker-systemd-service/issues/45
      ansible.builtin.file:
        path: /etc/default/<container name>
        owner: '{{ ansible_user }}'
        mode: '0644'

Typo in README.

The example defines myapp but the commentary uses the name mysql. Commentary should also use the name myapp.

Name space collision for the `state` default variable?

I have an Ansible role in which I include your role a number of times to have long running containers on a dedicated machine. I developed everything against Vagrant + the Ansible provisioner. Everything works like a charm.

Then came the time I had to roll it out on the AWS EC2 production machine. Bam, it broke on setting up the first docker systemd service with this error (when running Ansible with -vvv):

fatal: [10.130.20.211]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "daemon_reload": true,
            "enabled": true,
            "masked": false,
            "name": "elasticsearch_container.service",
            "no_block": false,
            "state": "{'code': 16, 'name': 'running'}",
            "user": false
        }
    },
    "msg": "value of state must be one of: reloaded, restarted, started, stopped, got: {'code': 16, 'name': 'running'}"
}

So the given state became {'code': 16, 'name': 'running'}. Googling this type of message structure always directs me to the boto Python AWS SDK library. While not really knowing how Ansible internals work, my assumption is that something of the boto usage leaks down in the namespace of the Ansible role variables. The value given above could easily be the state of the VM being checked first.

To test this, I renamed the default variable state in this role to service_state and updated the usages in install.yml. Executed my playbook again and with good results.

As I don't know Ansible well enough, I first created this ticket here. It might be the case that this is a valid case of Variable Precedence, but it might be that this collision is a core Ansible bug. In this case, I hope we can work together in the investigation before we file a bug in the Ansible core project.

[DEPRECATION WARNING]: "include" is deprecated, use include_tasks/import_tasks instead

When using the module, a deprecation warning is thrown during execution:

[DEPRECATION WARNING]: "include" is deprecated, use include_tasks/import_tasks instead. This feature will be removed in version 2.16. Deprecation warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.

Environment

ansible [core 2.13.4]
  config file = None
  configured module search path = ['/path/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/6.4.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/andy.grunwald/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.10.6 (main, Aug 30 2022, 04:58:14) [Clang 13.1.6 (clang-1316.0.21.2.5)]
  jinja version = 3.1.2
  libyaml = True

Support customization of the `[Unit]` section

I'm using this role to have systemd start docker containers, and some of these containers need a Samba share to be mounted locally. These mounts are described in /etc/fstab, causing systemd to automatically create associated .mount unit configurations. I'd like systemd to only start the container after the mount unit.

To do this, we'd need to be able to support an additional after parameter, empty by default, that would allow us to supercharge the unit after clause.

WDYT? I'm ready to provide the patch if you think this is a good idea. Thanks!

container_args not working

The container_args are rendered as

ExecStart=/usr/bin/docker run --name foo --rm --env-file /etc/default/foo  ['--add-host idadwh.db:10.0.1.3'] nginx:latest

Create v2.2.0 release for Ansible Galaxy

There have been a few useful changes since the 2.1.0 release currently on Galaxy. Could you make a new release to Galaxy so we can update to a stable version via our requirements.yml ? Thanks.

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.