I’m on ansible 2.6.3-1.el7 on CentOS 7.2 and i’m having problems with notify using include_tasks or import_tasks
This is that i want to achieve:
using a variable to pass the packages list to a task that use yum to install them
then if any packages is installed (changed state) notify two handlers (also them imported/included) passing the daemon to start/reload/restart/enable/disable/mask/unmask the daemon
So this is my playbook.yml
- hosts:
dyn194
tasks:
Install openafs client
- name: install openafs
import_tasks: /root/ansible/tasks/install_packages.yml
vars:
daemon_boot: “openafs-client”
daemon_reload: “openafs-client”
daemon_start: “openafs-client”
packages_to_install: - kernel-devel
- dkms-openafs
- openafs
- openafs-client
- openafs-docs
- openafs-krb5
notify: - start daemon
- enable start at boot of daemon
tags: opens
handlers:
-
import_tasks: /root/ansible/handlers/start_daemon.yml
-
import_tasks: /root/ansible/handlers/reload_daemon.yml
-
import_tasks: /root/ansible/handlers/enable_start_at_boot_daemon.yml
-
import_tasks: /root/ansible/handlers/restart_daemon.yml
this is my install_packages.yml
Task to install packages
- name: install packages
yum:
name: “{{ item }}”
state: present
with_items: “{{ packages_to_install }}”
this is my start_daemon.yml (handler task)
Start daemon daemon_start
-
name: start daemon
systemd:
name: “{{ daemon_start }}”
status: started -
debug:
msg: “daemon to start = {{ daemon_start }}”
listen: start daemon
this is my enable_start_at_boot_of_daemon (handler task)
Enable start at boot of the daemon_boot
-
name: enable start at boot of daemon
systemd:
name: “{{ daemon_boot }}”
enabled: yes -
debug:
msg: “daemon to start at boot = {{ daemon_boot }}”
listen: enable start at boot of daemon
Now when i run the playbook i get
PLAY [dyn194] ****************************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************************
ok: [dyn194]
TASK [install packages] ******************************************************************************************************************************************
changed: [dyn194] => (item=[u’kernel-devel’, u’dkms-openafs’, u’openafs’, u’openafs-client’, u’openafs-docs’, u’openafs-krb5’])
PLAY RECAP *******************************************************************************************************************************************************
dyn194 : ok=2 changed=1 unreachable=0 failed=0
the packages got installed but i don’t get the notifies to run the handlers
infact if i show the status of openafs-client i get
[root@dyn194 ~]# systemctl status openafs-client
● openafs-client.service - OpenAFS Client Service
Loaded: loaded (/usr/lib/systemd/system/openafs-client.service; disabled; vendor preset: disabled)
Active: inactive (dead)
so it is not started and not enabled and in any case i got the debug messages i put in the handlers
How can i solve this ?
Thanks in advance
Claudio