Ansible 2.2 : Restart process using variable in ha

2019-09-12 08:44发布

问题:

I want to do something like this :

 - copy: 
     src: file{{ item }}.xml
     dest: target_file{{ item }}.xml
   notify: restart process{{ item }}
   with_sequence: start=1 end={{ number_of_process }}

Expected result : the process 1 is restarted only if configuration file target_file1 has been modified, the process 2 is restarted only if configuration file target_file2 has been modified etc.

Real result is the restart of all process when one configuration file is modified.

Any idea to restart only the desired process ?

回答1:

Seems like a bug. I've filed the issue #22579.

If you need a workaround modify ansible/plugins/strategy/__init__.py:

            for result_item in result_items:
                if '_ansible_notify' in result_item:
                    # if task_result.is_changed(): # comment this line
                    if result_item['changed']:     # add this