Ansible notify handler with_items -


i'm adding java_opts environment variables through ansible multiple applications, , want restart application if java_opts changed.

what have task each application add environment variable , notify restart application like:

- name: add variable1   become: yes   lineinfile: dest=/etc/environment regexp='^variable1=' line='variable1={{variable1}}'   notify: restart application1  - name: restart application1   become: yes   command: restart application1 

as have many applications doing way means having lot of tasks. have task loop on applications using with_items. can't figure out how have 1 handler task restart. possible pass handler application needs restart? like:

- name: add variables   become: yes   lineinfile: dest=/etc/environment regexp='^{{item.app_name}}='   line='{{item.app_name}}={{ item.variable }}'   notify: restart apps   #pass app_name handler somehow   with_items:   - { variable: "first", app_name: "app1"}   - { variable: "second", app_name: "app2"}   - { variable: "third", app_name: "app3"}   - name: restart apps   become: yes   command: restart {{app_name}} 

you can emulate handler functionality registering values , looping on them in subsequent task (that second task may or may not defined handler):

- name: add variables   lineinfile:     dest: ./testfile     regexp: '^{{item.app_name}}='     line: '{{item.app_name}}={{ item.variable }}'   register: add_variables   with_items:     - { variable: "first", app_name: "app1"}     - { variable: "second", app_name: "app2"}     - { variable: "third", app_name: "app3"}  - name: restart apps   become: yes   command: restart {{item.item.app_name}}   when: item.changed   with_items: "{{ add_variables.results }}" 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -