mhutter / ansible-docker-systemd-service

Ansible role for creating Systemd services for docker containers
https://galaxy.ansible.com/mhutter/docker-systemd-service
MIT License
48 stars 30 forks source link

Fixed error when using external vars for defining container_name. #61

Closed epou closed 1 month ago

epou commented 1 year ago

Checklist

Since using the "service_name" variable (which by default already contains the "container_name" variable) to uniquely identify each service, no need to name the handlers too.

See: https://github.com/ansible/ansible/issues/63822


Error scenario: playbooks/site.yaml

- hosts: all
  become: true
  roles:
    - role1

group_vars/all.yaml

container_name: 'my_container_test'
container_image: 'my_image_test:latest'

roles1/tasks/main.yaml

- name: Dummy task
  debug:
     msg: "Hello world!"
- name: Including the role.
  include_role:
    name: mhutter.docker-systemd-service

Output:

[WARNING]: Handler 'restart container {{ container_name }}' is unusable because it has no listen topics and the name could not be templated (host-specific variables are not supported in handler names). The
error: {{ name }}: 'name' is undefined. 'name' is undefined. {{ name }}: 'name' is undefined. 'name' is undefined
ERROR! The requested handler 'restart container my_container_test' was not found in either the main handlers list nor in the listening handlers list
epou commented 1 year ago

@mhutter Did you have the chance to take a look at this? What are your thoughts?