{"id":231,"date":"2023-08-30T15:39:09","date_gmt":"2023-08-30T07:39:09","guid":{"rendered":"http:\/\/xianyijitan.top\/?p=231"},"modified":"2023-08-30T16:04:33","modified_gmt":"2023-08-30T08:04:33","slug":"ansible-%e9%80%9a%e8%bf%87-notify-%e8%a7%a6%e5%8f%91%e6%89%a7%e8%a1%8c-handlers-%e4%bb%bb%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/xianyijitan.top\/?p=231","title":{"rendered":"Ansible \u901a\u8fc7 notify \u89e6\u53d1\u6267\u884c handlers \u4efb\u52a1"},"content":{"rendered":"<h2>handlers\u4ecb\u7ecd<\/h2>\n<p><strong>\u5f53\u67d0\u4e2a\u4efb\u52a1\u9700\u8981\u4f9d\u8d56\u5176\u4ed6\u4efb\u52a1\u600e\u4e48\u529e\uff1f<\/strong><\/p>\n<p><strong>\u53ef\u4ee5\u901a\u8fc7handlers\u5b9a\u4e49\u89e6\u53d1\u6267\u884c\u7684\u4efb\u52a1\uff0c\u4f46\u6267\u884chandlers\u4e2d\u5b9a\u4e49\u7684\u4efb\u52a1\u662f\u6709\u6761\u4ef6\u7684\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u4ec5\u5f53\u67d0\u4e2a\u4efb\u52a1\u89e6\u53d1\uff08notify\uff09handlers\u65f6\u624d\u6267\u884c\u76f8\u5e94\u7684\u4efb\u52a1<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u5982\u679c\u6709\u591a\u4e2anotify\u89e6\u53d1\u6267\u884chandlers\u4efb\u52a1\uff0c\u4e5f\u4ec5\u6267\u884c\u4e00\u6b21<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u4ec5\u5f53\u4efb\u52a1\u7684\u6267\u884c\u72b6\u6001\u4e3achanged\u65f6handlers\u4efb\u52a1\u624d\u6267\u884c<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>handlers\u4efb\u52a1\u5728\u6240\u6709\u5176\u4ed6\u4efb\u52a1\u90fd\u6267\u884c\u540e\u624d\u6267\u884c<\/strong><\/p>\n<p><strong>\u901a\u8fc7notify\u89e6\u53d1\u6267\u884chandlers\u4efb\u52a1\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u200b       <strong>\u5148\u521b\u5efa\u6587\u4ef6\u5939\/tmp\/handa\/xixi\uff0c\u7136\u540e\u5728\u8be5\u6587\u4ef6\u5939\u91cc\u9762\u521b\u5efa\u6587\u4ef61.txt\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">[root@pubserver ansible]# vim handlres.yml\n---\n- name: handlers test\n  hosts: web1\n  tasks:\n    - name: create dir\n      file:                 # \u521b\u5efa\u6587\u4ef6\u5939\n        path: \/tmp\/handa\/xixi1\n        state: directory\n      notify: touch file    # \u901a\u77e5touch file \u9700\u8981\u6267\u884c\n\n  handlers:                 # \u6267\u884ctouche file\u4efb\u52a1\n    - name: touch file\n      file: \n        path: \/tmp\/handa\/xixi\/1.txt\n        touch: touch\n\n# \u7b2c\u4e00\u6b21\u6267\u884c\uff0c\u4efb\u52a1\u4e00\u6210\u529f\u6267\u884c\uff0c\u4efb\u52a1\u4e8c\u6267\u884c\u5931\u8d25\n[root@pubserver ansible]# ansible-playbook handlres.yml\n\nPLAY [handlers test] ******************************************************************************************************************************\n\nTASK [Gathering Facts] ****************************************************************************************************************************\nok: [web1]\n\nTASK [create dir] *********************************************************************************************************************************\nchanged: [web1]\n\nRUNNING HANDLER [touch file] **********************************************************************************************************************\nfatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Unsupported parameters for (file) module: touch Supported parameters include: _diff_peek, _original_basename, access_time, access_time_format, attributes, backup, content, delimiter, directory_mode, follow, force, group, mode, modification_time, modification_time_format, owner, path, recurse, regexp, remote_src, selevel, serole, setype, seuser, src, state, unsafe_writes&quot;}\n\nNO MORE HOSTS LEFT ********************************************************************************************************************************\n\nPLAY RECAP ****************************************************************************************************************************************\nweb1                       : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   \n\n# \u7b2c\u4e8c\u6b21\u6267\u884c\uff0c\u4efb\u52a1\u5168\u90e8\u6267\u884c\u6210\u529f\n[root@pubserver ansible]# ansible-playbook handlres.yml\n\nPLAY [handlers test] ******************************************************************************************************************************\n\nTASK [Gathering Facts] ****************************************************************************************************************************\nok: [web1]\n\nTASK [create dir] *********************************************************************************************************************************\nok: [web1]\n\nPLAY RECAP ****************************************************************************************************************************************\nweb1                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>handlers\u4ecb\u7ecd \u5f53\u67d0\u4e2a\u4efb\u52a1\u9700\u8981\u4f9d\u8d56\u5176\u4ed6\u4efb\u52a1\u600e\u4e48\u529e\uff1f \u53ef\u4ee5\u901a\u8fc7handlers\u5b9a\u4e49\u89e6\u53d1\u6267\u884c\u7684\u4efb\u52a1\uff0c\u4f46\u6267\u884chandlers\u4e2d\u5b9a\u4e49\u7684\u4efb\u52a1\u662f\u6709\u6761\u4ef6\u7684\uff1a \u4ec5\u5f53\u67d0\u4e2a\u4efb\u52a1\u89e6\u53d1\uff08notify\uff09handlers\u65f6\u624d\u6267\u884c\u76f8\u5e94\u7684\u4efb\u52a1 \u5982\u679c\u6709\u591a\u4e2anotify\u89e6\u53d1\u6267\u884chandlers\u4efb\u52a1\uff0c\u4e5f\u4ec5\u6267\u884c\u4e00\u6b21 \u4ec5\u5f53\u4efb\u52a1\u7684\u6267\u884c\u72b6\u6001\u4e3achanged\u65f6handlers\u4efb\u52a1\u624d\u6267\u884c handlers\u4efb\u52a1\u5728\u6240\u6709\u5176\u4ed6\u4efb\u52a1\u90fd\u6267\u884c\u540e\u624d\u6267\u884c \u901a\u8fc7notify\u89e6\u53d1\u6267\u884chandlers\u4efb\u52a1\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a \u200b \u5148\u521b\u5efa\u6587\u4ef6\u5939\/tmp\/handa\/xixi\uff0c\u7136\u540e\u5728\u8be5\u6587\u4ef6\u5939\u91cc\u9762\u521b\u5efa\u6587\u4ef61.txt\uff1a [root@pubserver ansible]# vim handlres.yml &#8212; &#8211; name: handlers test hosts: web1 tasks: &#8211; name: create dir file: # \u521b\u5efa\u6587\u4ef6\u5939 path: \/tmp\/handa\/xixi1 state: directory notify: touch file # \u901a\u77e5touch file \u9700\u8981\u6267\u884c handlers: # \u6267\u884ctouche file\u4efb\u52a1 &#8211; name: touch file file: path: \/tmp\/handa\/xixi\/1.txt touch: touch # \u7b2c\u4e00\u6b21\u6267\u884c\uff0c\u4efb\u52a1\u4e00\u6210\u529f\u6267\u884c\uff0c\u4efb\u52a1\u4e8c\u6267\u884c\u5931\u8d25 [root@pubserver ansible]# ansible-playbook handlres.yml PLAY [handlers test] ****************************************************************************************************************************** TASK [Gathering Facts] **************************************************************************************************************************** ok: [web1] TASK [create dir] ********************************************************************************************************************************* changed: [web1] RUNNING HANDLER [touch file] ********************************************************************************************************************** fatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Unsupported parameters for (file) module: touch Supported parameters include: _diff_peek, _original_basename, access_time, access_time_format, attributes, backup, content, delimiter, directory_mode, follow, force, group, mode, modification_time, modification_time_format, owner, path, recurse, regexp, remote_src, selevel, serole, setype, seuser, src, state, unsafe_writes&quot;} NO MORE HOSTS LEFT ******************************************************************************************************************************** PLAY RECAP *****************************************************************************************************************&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-lixx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=231"}],"version-history":[{"count":3,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}