geerlingguy / ansible-role-php

Ansible Role - PHP
https://galaxy.ansible.com/geerlingguy/php/
MIT License
496 stars 441 forks source link

Cannot use handlers from this role if running playbook with tags #348

Closed sebastianmacarescu closed 2 years ago

sebastianmacarescu commented 2 years ago

I'm using this role in a task with tags as follows: - name: Create .env file ansible.builtin.template: src: .env.j2 dest: "{{ install_path }}/.env" notify: restart webserver tags: ['configuration', 'configuration:app']

I'm running the playbook with --tags "configuration:app"

I get the following error: `msg: |- The task includes an option with an undefined variable. The error was: 'php_fpm_daemon' is undefined

The error appears to be in '/root/.ansible/roles/geerlingguy.php/handlers/main.yml': line 9, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: restart php-fpm
  ^ here`

The solution is pretty simple. Add always tag for all tasks in this role that load variables. https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html#special-tags-always-and-never

That is:

I can provide a PR if needed

stale[bot] commented 2 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

racke commented 2 years ago

Yes that makes sense to me. I'm already using that approach for one of my roles.

stale[bot] commented 2 years ago

This issue is no longer marked for closure.

racke commented 2 years ago

It will be difficult to fix that though, because the tasks defining the variables are all over the place. Also the role uses include_tasks instead of import_tasks, so always tag wouldn't help for these tasks.

stale[bot] commented 2 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] commented 2 years ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.