Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

epou
Copy link
Contributor

@epou epou commented Jun 1, 2023

Checklist

  • Keep pull requests small so they can be easily reviewed.
  • Link this PR to related issues.

Changes:

  • Removed dynamic naming of handlers.
  • Allow defining 'container_name' variable using a group_var/host_var.
  • No need to define 'container_name' in a static way when including this role.

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: ansible/ansible#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
Copy link
Contributor Author

epou commented Jun 7, 2023

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

@mhutter mhutter merged commit 1a25a62 into mhutter:master Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants