Questions tagged [ansible-handlers]

28 questions
76
votes
1 answer

How to force handler to run before executing a task in Ansible?

I have a playbook which should configure on specified IP, and than connect to this app to configure stuff inside. I've got a problem: I need to restart app after I've changed anything in app config, and if I do not restart app, connection to it…
George Shuklin
  • 6,952
  • 10
  • 39
  • 80
7
votes
4 answers

Run an Ansible handler only once for the entire playbook

I would like to run a handler only once in an entire playbook. I attempted using an include statement in the following in the playbook file, but this resulted in the handler being run multiple times, once for each play: - name: Configure common…
user3155618
  • 359
  • 1
  • 5
  • 14
4
votes
1 answer

Ansible not detecting Role default variables in its handler

Does ansible pass Role Default variables to the Handlers within the same Role? Here's a minimal excerpt of the playbook that has the issue: Role hierarchy - playbook.yml - roles/ - gunicorn/ - defaults/ - main.yml - handlers/ -…
rtindru
  • 5,107
  • 9
  • 41
  • 59
3
votes
0 answers

How can I skip redundant Ansible handlers?

Imagine the following playbook, which manages a systemd service unit and a configuration file for a "thing" service: --- - hosts: all tasks: - copy: src: thing.service dest: /etc/systemd/system/thing.service notify: restart…
3
votes
0 answers

Ansible not executing handlers from dependency roles for all hosts

Setup I have several roles which declare role dependencies and sometimes use handlers from roles they depend on. A simplified version of my setup looks like this (This is the output of head inventory **/*.yml and it shows all path names and the…
2
votes
1 answer

Execute Ansible reboot with handler only when required

I have the following file structure: $ tree roles/os roles/os ├── handlers │   └── main.yaml └── tasks └── main.yaml tasks/main.yaml: --- - name: Upgrade all packages ansible.builtin.apt: update_cache: true upgrade: dist - name:…
Floren
  • 113
  • 11
2
votes
2 answers

Ansible handler - not called from rescue block

Consider the following (reduced for brevity) playbook with a block and rescue block - name: deploy block block: - name: debug meta debug: var=meta - name: create/update configmap with new data k8s: state: present …
alonisser
  • 11,542
  • 21
  • 85
  • 139
2
votes
1 answer

Ansible handler using if statements

I have an apache playbook which needs to run on centos 7 and centos 6. I want the handler triggered based on distribution major version. I have a handler called restart apache on 7 and another one restart apache on 6. My handlers/main.yml looks…
crusadecoder
  • 651
  • 1
  • 11
  • 26
2
votes
1 answer

Ansible won't see a handler when using the group_by

I used to have simple playbook (something like this) which I run on all over my machines (RH & Debian based) to update them, and for each machine which was updated run a script (notify handler). Recently I tried to test a new module called group_by,…
Rabin
  • 826
  • 10
  • 21
1
vote
1 answer

handler not executing using when condition in task

I'm trying to set up an NFS share between two nodes using Ansible. I'm using the role nfs, which is executed by both nodes, and I separated client and server tasks using the when condition. After templating the NFS /etc/exports on the server node I…
1
vote
1 answer

Ansible: How to do a loop to call series of handler tasks?

I'm quite new to ansible and I have been working on writing an ansible role to automate the incremental upgrade process for Jenkins. Part of this process has involved creating a loop which executes on the condition that the current version of…
Bert
  • 83
  • 3
1
vote
1 answer

Wait for handler for every item in with_lines - Ansible

Ansible Version: ansible 2.4.2.0 I want to start VM sequentially depends on the role(master/backup). Multiple VM IDs are stored in 2 files master & backup. The controller flow should like below Iterate VM IDs one by one from a file For every…
Veerendra K
  • 2,145
  • 7
  • 32
  • 61
1
vote
1 answer

Handlers not getting invoked after a task

I am trying to automate some tasks using Ansible. In my playbooks, I have a copy task and then i change the permissions of the file. I need the service to restart after this task. I am including notify and have also declared my handler, but…
Gaurav Parashar
  • 1,347
  • 2
  • 19
  • 21
1
vote
1 answer

Ansible notify handler with_items

I'm adding JAVA_OPTS as environment variables through ansible for multiple applications, and I want to restart an application if JAVA_OPTS changed. What I have now is a task for each application to add the environment variable and a notify to…
A.Jac
  • 1,443
  • 3
  • 17
  • 24
1
vote
1 answer

Ansible handler read local fact

I have an Ansible playbook to install a variable number of applications in a group of servers. To install the applications, a number of sequential tasks have to run, and since there may be several applications, I loop through them with with_items: I…
felichas
  • 77
  • 1
  • 1
  • 4
1
2